'a'.tap { |it| it << 'b' } # => 'ab'We can't use += as this is assignment and creates a new object which is not returned:
'a'.tap { |it| it += 'b' } # => 'a''a'.itself { |it| it << 'b' } # => 'a'Using itself the block does not seem to be executed, e.g. 'a'.itself { raise } does not raise.
We could also use yield_self but this only works because << returns the new string.
'a'.yield_self { |it| it << 'b' } # => 'ab'The result of the block is returned, not the reciver (original string):
'a'.yield_self { |it| it << 'b'; v } # => 'v'