try was originally defined as:
class Object
def try(method)
send method if respond_to? method
end
end
In Rails it is defined as: class Object
alias_method :try, :__send__
end
class NilClass
def try(*args)
nil
end
end
The following code will exhibit different behavior depending on which version of try you're using: [].try :upcase
For example: # original try
>> [].try :upcase
=> nil
# rails try
>> [].try :upcase
NoMethodError: undefined method `upcase' for []:Array
If Rails uses try internally, and a Rails plugin you've loaded depends on the original version of try, what now? They both behave differently and, presumably, code using them depends on their specific behavior.Also don't forget the dozen or so other versions of try people have added to their own plugins and apps...