Class: Proc
Instance Method Summary collapse
-
#yield_or_eval(object) ⇒ Object
Yield or instance evaluate the
object
passed based on this proc’s arity.
Instance Method Details
#yield_or_eval(object) ⇒ Object
Yield or instance evaluate the object
passed based on this proc’s arity.
Examples
def foo &block
block.yield_or_eval 'bar'
end
foo { |v| v.length } # => 3
foo { length } # => 3
18 19 20 |
# File 'lib/rext/proc/helpers.rb', line 18 def yield_or_eval object arity > 0 ? self.call(object) : object.instance_eval(&self) end |