Last change
on this file since 331 was 321, checked in by coas-nagasima, 7 years ago |
文字コードを設定
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby;charset=UTF-8
|
File size:
617 bytes
|
Line | |
---|
1 | class Object
|
---|
2 | ##
|
---|
3 | # call-seq:
|
---|
4 | # obj.tap{|x|...} -> obj
|
---|
5 | #
|
---|
6 | # Yields <code>x</code> to the block, and then returns <code>x</code>.
|
---|
7 | # The primary purpose of this method is to "tap into" a method chain,
|
---|
8 | # in order to perform operations on intermediate results within the chain.
|
---|
9 | #
|
---|
10 | # (1..10) .tap {|x| puts "original: #{x.inspect}"}
|
---|
11 | # .to_a .tap {|x| puts "array: #{x.inspect}"}
|
---|
12 | # .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}
|
---|
13 | # .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}
|
---|
14 | #
|
---|
15 | def tap
|
---|
16 | yield self
|
---|
17 | self
|
---|
18 | end
|
---|
19 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.