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

User.name?

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

!User.name.blank?

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

  • DZone
  • Twitter
  • Slashdot
  • Delicious
  • Digg
  • Technorati Favorites
  • Facebook
  • Reddit
  • StumbleUpon
  • LiveJournal
  • Squidoo
  • Google Bookmarks
  • LinkedIn
  • Share/Bookmark

2 Comments »

» Quick Tip: Knowing if an Object's Attribute is Empty or Nil Wordpress Hosting: Just another WordPress weblog

June 19, 2009

[...] Visit link: Quick Tip: Knowing if an Object's Attribute is Empty or Nil [...]

pawut

June 20, 2009

thank good site

Leave a comment