/ Published in: Ruby
The Object#tap method can be plugged between elements of a method chain and perform various operations on an intermediate result of a calculation.
Expand |
Embed | Plain Text
# encoding: utf-8 'one two three' .split .tap { |x| p x } .collect(&:upcase) .tap { |x| p x } .join(' ') .tap { |x| p x } #=> ["one", "two", "three"] # ["ONE", "TWO", "THREE"] # "ONE TWO THREE"
You need to login to post a comment.
