Flowdock

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?
Show files where this class is defined (1 file)
Register or log in to add new notes.
June 20, 2012 - (v2.2.1 - v3.2.3)
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
June 13, 2012
0 thanks

Example of usage

e.g.

str = ActiveSupport::StringInquirer.new('test')

str.test? # => true
str.foobar? # => false
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