User.find(5).email
- will blow up if 'email' property is not present
User.find(5).try(:email)
- will return 'nil' if 'email' property is not present
- will blow up if 'email' property is not present
User.find(5).try(:email)
- will return 'nil' if 'email' property is not present
respond_to?
is a Ruby method for detecting whether the class has a particular method on it.@user.respond_to?('eat_food')
No comments:
Post a Comment