1. 7
  1.  

  2. 4

    Ouch! The #try! thing in Rails 4 reeks of PHP’s mysql_unescape_real though.

    1. 5

      try_but_not_too_hard

    2. 1

      This is especially frustrating because they changed the behavior of #try in Rails 4.0 and added #try! with the old behavior.

      1. 2

        I thought #try was the same, but they added #try! which would basically do what Avdi was implying #try should already be doing?

        1. 1

          In Rails 3.2.22, #try says:

          Invokes the method identified by the symbol method … just like the regular Ruby Object#send does. Unlike that method however, a NoMethodError exception will not be raised and nil will be returned instead, if the receiving object is a nil object or NilClass.

          http://api.rubyonrails.org/v3.2.22/classes/Object.html#method-i-try

          But in Rails 4.0.0 it says:

          Invokes the public method whose name goes as first argument just like public_send does, except that if the receiver does not respond to it the call returns nil rather than raising an exception.

          http://api.rubyonrails.org/v4.0.0/classes/Object.html#method-i-try