public Method

Object.returning(value) { |value| ... }

A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.

def foo
  returning values = [] do
    values << 'bar'
    values << 'baz'
  end
end

foo # => ['bar', 'baz']

def foo
  returning [] do |values|
    values << 'bar'
    values << 'baz'
  end
end

foo # => ['bar', 'baz']

Source Code

# File active_support/core_ext/object/misc.rb, line 27
def returning(value)
  yield(value)
  value
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.