Can someone explain the following behavior? They both should return the same.
@properties.filtros_hash
=> {"casa"=>"sim"}
@properties.try(:filtros_hash)
=> nil
"sim"} @properties.try(:filtros_has" /> "sim"} @properties.try(:filtros_has" /> "sim"} @properties.try(:filtros_has"/>
Can someone explain the following behavior? They both should return the same.
@properties.filtros_hash
=> {"casa"=>"sim"}
@properties.try(:filtros_hash)
=> nil
@properties, in my case, was an instance of a SimpleDelegator. Something like this:
Having that in mind, and reading Rails's documentation about
.try, I found out this:So, that explains this highly unexpected behavior, since even tough PropertiesDecorator have a
filtros_hashinstance method, by using .try thefiltros_hashis being delegated to @properties (ActiveRecord) where there is no such method.