Ruby on Rails latest stable (v5.2.3)
-
3 notes
- Superclass:
String
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1 (0)
- 2.3.2 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-5)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (38)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- What's this?
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)
stevo -
June 13, 2012
linjunpop -
May 23, 2013

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

0 thanks
Example of usage
e.g.
str = ActiveSupport::StringInquirer.new('test') str.test? # => true str.foobar? # => false

0 thanks
A simple usage example
See http://apidock.com/rails/String/inquiry
env = "production".inquiry env.production? # => true env.development? # => false