Sha256: 0a279e6b7f7d7238654cd6bd43f0be954d449d96dca5cc82b299d26e12a6d886

Contents?: true

Size: 927 Bytes

Versions: 13

Compression:

Stored size: 927 Bytes

Contents

class Object
  # Returns +value+ after yielding +value+ to the block. This simplifies the
  # process of constructing an object, performing work on the object, and then
  # returning the object from a method. It is a Ruby-ized realization of the K
  # combinator, courtesy of Mikael Brockman.
  #
  # ==== Examples
  #
  #  # Without returning
  #  def foo
  #    values = []
  #    values << "bar"
  #    values << "baz"
  #    return values
  #  end
  #
  #  foo # => ['bar', 'baz']
  #
  #  # returning with a local variable
  #  def foo
  #    returning values = [] do
  #      values << 'bar'
  #      values << 'baz'
  #    end
  #  end
  #
  #  foo # => ['bar', 'baz']
  #
  #  # returning with a block argument
  #  def foo
  #    returning [] do |values|
  #      values << 'bar'
  #      values << 'baz'
  #    end
  #  end
  #
  #  foo # => ['bar', 'baz']
  def returning(value)
    yield(value)
    value
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
csd-0.1.5 lib/active_support/core_ext/object/returning.rb
csd-0.1.4 lib/active_support/core_ext/object/returning.rb
csd-0.1.3 lib/active_support/core_ext/object/returning.rb
csd-0.1.2 lib/active_support/core_ext/object/returning.rb
csd-0.1.1 lib/active_support/core_ext/object/returning.rb
csd-0.1.0 lib/active_support/core_ext/object/returning.rb
csd-0.0.16 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.0.beta4 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.0.beta3 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.0.beta2 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.0.beta lib/active_support/core_ext/object/returning.rb
activesupport-3.0.pre lib/active_support/core_ext/object/returning.rb
recliner-0.0.1 vendor/activesupport/lib/active_support/core_ext/object/returning.rb