class
Wrapping a string in this class gives you a prettier way to test for equality. The value returned by Rails.env is wrapped in a StringInquirer object, so instead of calling this:
Rails.env == 'production'
you can call this:
Rails.env.production?
Instantiating a new StringInquirer
vehicle = ActiveSupport::StringInquirer.new('car') vehicle.car? # => true vehicle.bike? # => false
Register or
log in
to add new notes.
meceo -
June 20, 2012 - (>= v2.2.1)
1 thank
Another usage example
given: order active record class with “state” string field
class Order < ActiveRecord::Base def state @state ||= ActiveSupport::StringInquirer.new(read_attribute(:status)) end end order = Order.new(state: "initial") order.state.initial? #=> true order.state.paid? #=> false
stevo -
June 13, 2012
0 thanks
Example of usage
e.g.
str = ActiveSupport::StringInquirer.new('test') str.test? # => true str.foobar? # => false
linjunpop -
May 23, 2013
0 thanks
A simple usage example
See http://apidock.com/rails/String/inquiry
env = "production".inquiry env.production? # => true env.development? # => false