rails/rails — pull request #14596 by shhavel (2014-04-04 13:10:03+00:00)
Title: Add Object#tie method

If receives some arguments:
invokes the public method whose name goes as first argument just like
+public_send+ does,
except if first argument is nil it returns receiver itself.

Also can be called with block only (and no arguments).
In this case method returns result of block call (whith receiver as block argument)
or receiver itself (if block returns nil or false).

Method is intended for creating conditional method chains, e.g.:

`"test".reverse.next.concat("45").tie((:upcase if do_upcase?))`

or

`"test".reverse.next.concat("45").tie {|s| s.upcase if do_upcase? }`

instead of

`if do_upcase?`
`"test".reverse.next.concat("45").upcase`
`else`
`"test".reverse.next.concat("45")`
`end`

or

`s = "test".reverse.next.concat("45")`
`s = s.upcase if do_upcase?`
`s`

Raises ArgumentError if called without any arguments and without block.