File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
activesupport/lib/active_support/core_ext Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 2
2
require 'active_support/core_ext/object/blank'
3
3
require 'active_support/core_ext/object/duplicable'
4
4
require 'active_support/core_ext/object/try'
5
+ require 'active_support/core_ext/object/returning'
5
6
6
7
require 'active_support/core_ext/object/conversions'
7
8
require 'active_support/core_ext/object/instance_variables'
Original file line number Diff line number Diff line change
1
+ class Object
2
+ # Returns +value+ after yielding +value+ to the block. This simplifies the
3
+ # process of constructing an object, performing work on the object, and then
4
+ # returning the object from a method. It is a Ruby-ized realization of the K
5
+ # combinator, courtesy of Mikael Brockman.
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # # Without returning
10
+ # def foo
11
+ # values = []
12
+ # values << "bar"
13
+ # values << "baz"
14
+ # return values
15
+ # end
16
+ #
17
+ # foo # => ['bar', 'baz']
18
+ #
19
+ # # returning with a local variable
20
+ # def foo
21
+ # returning values = [] do
22
+ # values << 'bar'
23
+ # values << 'baz'
24
+ # end
25
+ # end
26
+ #
27
+ # foo # => ['bar', 'baz']
28
+ #
29
+ # # returning with a block argument
30
+ # def foo
31
+ # returning [] do |values|
32
+ # values << 'bar'
33
+ # values << 'baz'
34
+ # end
35
+ # end
36
+ #
37
+ # foo # => ['bar', 'baz']
38
+ def returning ( value )
39
+ ActiveSupport ::Deprecation . warn ( 'Object#returning has been deprecated in favor of Object#tap.' , caller )
40
+ yield ( value )
41
+ value
42
+ end
43
+ end
You can’t perform that action at this time.
0 commit comments