Method: Kernel#ergo

Defined in:
lib/core/facets/kernel/ergo.rb

#ergo(&b) ⇒ Object

Yield self -or- return self.

"a".ergo.upcase #=> "A"
nil.ergo.foobar #=> nil

"a".ergo{ |o| o.upcase } #=> "A"
nil.ergo{ |o| o.foobar } #=> nil

This is like #tap, but #tap yields self and returns self, where as #ergo yields self but returns the result.

CREDIT: Daniel DeLorme


18
19
20
21
22
23
24
# File 'lib/core/facets/kernel/ergo.rb', line 18

def ergo(&b)
  if block_given?
    b.arity == 1 ? yield(self) : instance_eval(&b)
  else
    self
  end
end