Skip to content

Commit

Permalink
Bring returning back to ease migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 2, 2010
1 parent 9effe3c commit 88b5f93
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions activesupport/lib/active_support/core_ext/object.rb
Expand Up @@ -2,6 +2,7 @@
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'
Expand Down
43 changes: 43 additions & 0 deletions activesupport/lib/active_support/core_ext/object/returning.rb
@@ -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

0 comments on commit 88b5f93

Please sign in to comment.