Quick Tip: Knowing if an Object’s Attribute is Empty or Nil

I was browsing the ActiveRecord documentation and I came across notation that looks like this:


When I looked more closely, I realized that it replaced all of the places where I had something like this:


In other words, if the user’s name is an empty string (“”) or nil, I can call User.name? and it’ll return false. Here’s the documentation I was browsing. http://api.rubyonrails.org/classes/ActiveRecord/Base.html

{ 1 comment… read it below or add one }

pawut June 20, 2009 at 6:37 am

thank good site


Leave a Comment

{ 1 trackback }