rails/rails — pull request #11589 by charliesome (2013-07-25 01:44:08+00:00)
Title: Make try with no arguments return a TryProxy

I often see code along the lines of:

```ruby
foo.try(:[], 0)
```

I find this harder to read than it should be.

This pull request changes the `try` method so that it returns an `ActiveSupport::TryProxy` when called without arguments. This proxy then forwards any methods sent to it to the original object.

This does not break existing functionality. At the moment, calling `try` with no arguments raises an exception:

```irb
>> 123.try
TypeError: nil is not a symbol
from /Users/charlie/.gem/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/core_ext/object/try.rb:45:in `respond_to?'
>> 123.try!
ArgumentError: no method name given
from /Users/charlie/.gem/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/core_ext/object/try.rb:55:in `public_send'
```