Sha256: 52debf99753416eef14e1927536b4a5e9a20ee62e728b9c5abc6b2ce7216e388

Contents?: true

Size: 1.01 KB

Versions: 41

Compression:

Stored size: 1.01 KB

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)
    ActiveSupport::Deprecation.warn('Object#returning has been deprecated in favor of Object#tap.', caller)
    yield(value)
    value
  end
end

Version data entries

41 entries across 41 versions & 3 rubygems

Version Path
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/core_ext/object/returning.rb
activesupport-3.0.20 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.19 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.18 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.17 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.16 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.15 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.14 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.13 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.13.rc1 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.12 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.12.rc1 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.11 lib/active_support/core_ext/object/returning.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/core_ext/object/returning.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/core_ext/object/returning.rb
activesupport-3.0.10 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.10.rc1 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.9 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.9.rc5 lib/active_support/core_ext/object/returning.rb
activesupport-3.0.9.rc4 lib/active_support/core_ext/object/returning.rb