DEV Community

Rails's .try vs Ruby's &. (a.k.a safe navigation)

Tomas Valent on March 08, 2023

Rails #try vs Ruby's &. User.try(:cat) # => nil User.try(:name) # => "User" User&.cat # NoMethodError: undefined method `cat' for ...
Collapse
 
equivalent profile image
Tomas Valent

Big thanks to varandasi for pointing this out 😇