class
ActiveSupport::StringInquirer
v4.2.7 -
Show latest stable
- Superclass: String
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?
Files
- activesupport/lib/active_support/string_inquirer.rb
3Notes
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
Example of usage
e.g.
str = ActiveSupport::StringInquirer.new('test')
str.test? # => true
str.foobar? # => false
A simple usage example
See http://apidock.com/rails/String/inquiry
env = "production".inquiry
env.production? # => true
env.development? # => false