Module: Proc::ValueClassPatch

Included in:
Proc
Defined in:
lib/proc/value.rb

Instance Method Summary collapse

Instance Method Details

#val(proc_or_object, *args) ⇒ Object

Evaluate block if block is given or return unmodified object if no block is given. Additional arguments are given to ‘Proc#call`.

Can be used to allow transparent usage of blocks.

Examples:

config_option = Proc.val(config_option).to_s

See Also:

  • Object#value
  • Proc#value


15
16
17
# File 'lib/proc/value.rb', line 15

def val(proc_or_object, *args)
  proc_or_object.respond_to?(:call) ? proc_or_object.call(*args) : proc_or_object
end