# bad
email_with_name = user.name + ' <' + user.email + '>'
# good
email_with_name = "#{user.name} <#{user.email}>"
# better
email_with_name = "%s <%s>" % [user.name, user.email] # bad
email_with_name = user.name + ' <' + user.email + '>'
# good
email_with_name = "#{user.name} <#{user.email}>"
# better
email_with_name = "%s <%s>" % [user.name, user.email] email_with_name = "%s <%s>" % [user.name, user.email]
can be easily identified even when many fields are added.On the contrary, strings like
email_with_name = "#{user.name} <#{user.email}>"
become quite cramped as soon as you use three or more fields. puts "#{num} #{vessels} of #{liquid} on the #{where}, you #{verb1} one #{adverb1}, #{verb2} it #{adverb2}, #{num - 1} #{vessels} of #{liquid} on the #{where}"
puts "%d %s of %s on the %s, you %s one %s, %s it %s, %i %s of %s on the %s", [ num, vessels, liquid, where, verb1, adverb1, verb2, adverb2, num - 1 ]
It's an extreme example, but you just read the first, while you have to think about the second.