irb(main):001:0> def foo(x)
irb(main):002:1> x * 10
irb(main):003:1> end
=> nil
irb(main):004:0> def bar(y)
irb(main):005:1> y + 3
irb(main):006:1> end
=> nil
irb(main):007:0> foo(10).tap{|x| bar(x)}
=> 100
I was hoping this method would allow for the chaining of methods without assigning local variables, i.e. to return 103 instead of 100. What's going on here?
Perhaps the
tapdocumentation can clear it up?You want it to return
y, but it doesn't do that, it returnsxback to the chain.It's effectively doing: