Module: Riffer::Helpers::CallOrValue
Overview
Resolves the Proc-or-value idiom.
Instance Method Summary collapse
-
#resolve(thing, context: nil, default: nil) ⇒ Object
Calls
thingwhen it’s a Proc (passingcontextif its arity is non-zero), returns it unchanged otherwise, ordefaultwhennil.
Instance Method Details
#resolve(thing, context: nil, default: nil) ⇒ Object
Calls thing when it’s a Proc (passing context if its arity is non-zero), returns it unchanged otherwise, or default when nil. – : (untyped, ?context: untyped, ?default: untyped) -> untyped
12 13 14 15 16 |
# 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 |