tap method in Ruby 1.9

str = "Hello GG"

str.tap {|x| puts "str : #{x}"}
  .each_char.tap {|x| puts "each_char : #{x}"}
  .sort.tap {|x| puts "sort : #{x}"}

Output

str : Hello GG
each_char : #
sort : [" ", "G", "G", "H", "e", "l", "l", "o"]
Thursday, December 31, 2009