I have a Door
object that has a state
attribute of type string
. It can only be one of these elements: %w[open shut locked]
.
Are there any implications or reasons for using strings over symbols?
door.update_attributes(state: :open)
door.update_attributes(state: 'open')
In Rails 4 we can do this:
Door.order(created_at: :desc)
So why shouldn't I do this?
Door.where(state: :open) # vs state: 'open'
Are they equivalent for all intents and purposes? I prefer to use a symbol because it looks cleaner, and in the DB, a symbol will be a string anyway.