Test for String Equality
In Rails, there is an nice and easy interface that can be used to check a string for equality.
To do this, you can use the ActiveSupport::StringInquirer
object. Simply initialize it with a string value, like so:
string = ActiveSupport::StringInquirer.new("vanilla")
and now we can just call string#vanilla?
to check for equality
string.vanilla?
=> true
string.chocolate?
=> false
Fun fact:
This is how you are able to do Rails.env.production?
H/T: Matt Polito
Tweet