module Riffer::Helpers::CallOrValue
Resolves the Proc-or-value idiom.
Public Instance Methods
Source
# File lib/riffer/helpers/call_or_value.rb, line 12 def resolve(thing, context: nil, default: nil) return default if thing.nil? return thing unless thing.is_a?(Proc) thing.arity.zero? ? thing.call : thing.call(context) end
Calls thing when itβs a Proc (passing context if its arity is non-zero), returns it unchanged otherwise, or default when nil.