1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Bring returning back to ease migration.

This commit is contained in:
José Valim 2010-08-02 18:40:20 +02:00
parent 9effe3cc18
commit 88b5f938cf
2 changed files with 44 additions and 0 deletions

View file

@ -2,6 +2,7 @@ require 'active_support/core_ext/object/acts_like'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/object/try'
require 'active_support/core_ext/object/returning'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/object/instance_variables'

View file

@ -0,0 +1,43 @@
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