Symbols vs Strings April 22nd, 2008
When to use Symbols and when to use Strings in Ruby is really a personal preference. Most of the time I program without taking the difference in performance in consideration.
I just use a few simple rules
in a hash it’s always :key => ‘value’
redirect_to :controller => 'pages', :action => 'index'
special keywords are symbols
Page.find(:all) Page.find(:first) redirect_to(:back)
attributes and status’es are symbols
update_attribute(:name, 'Jan') comment.state = :approved
Except for those rules it’s really what feels right while coding it.
l
Yes, it’s a personal preference the same way which side of the street to drive on is a personal preference. You can get where you’re going on either side of the street, but if you drive on the wrong side you’re eventually going to get hurt.