I am following along with the Rails 3 in Action book, and it is talking about override to_s
in the model. The code is the following:
def to_s
It's string interpolation. "#{email} (#{admin? ? "Admin" : "User"})"
is equivalent to
email.to_s + " (" + (admin? ? "Admin" : "User") + ")"
that is
email.to_s + " (" + if admin? then "Admin" else "User" end + ")"
As a result of being enclosed in quotes, in this context Admin
and User
are used as strings and not as constants.