-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring returning back to ease migration.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
activesupport/lib/active_support/core_ext/object/returning.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |