Last change
on this file since 270 was 270, checked in by coas-nagasima, 7 years ago |
mruby版ECNLプロトタイピング・ツールを追加
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby
|
File size:
617 bytes
|
Rev | Line | |
---|
[270] | 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.