Sha256: 1132b857178f08a856a6efd349c754fcde37d37a826714100fc787f7cfd24869

Contents?: true

Size: 833 Bytes

Versions: 46

Compression:

Stored size: 833 Bytes

Contents

module ActiveSupport
  # Wrapping a string in this class gives you a prettier way to test
  # for equality. The value returned by <tt>Rails.env</tt> 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
  class StringInquirer < String
    private

      def respond_to_missing?(method_name, include_private = false)
        (method_name[-1] == "?") || super
      end

      def method_missing(method_name, *arguments)
        if method_name[-1] == "?"
          self == method_name[0..-2]
        else
          super
        end
      end
  end
end

Version data entries

46 entries across 46 versions & 5 rubygems

Version Path
hyperstack-config-1.0.alpha1.8 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.alpha1.7 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.alpha1.6 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.alpha1.5 lib/hyperstack/active_support_string_inquirer.rb
activesupport-5.1.7 lib/active_support/string_inquirer.rb
activesupport-5.1.7.rc1 lib/active_support/string_inquirer.rb
activesupport-5.1.6.2 lib/active_support/string_inquirer.rb
hyperstack-config-1.0.alpha1.4 lib/hyperstack/active_support_string_inquirer.rb
hyperloop-config-0.99.6 lib/hyperloop/active_support_string_inquirer.rb
hyperstack-config-1.0.alpha1.3 lib/hyperstack/active_support_string_inquirer.rb
hyperloop-config-0.99.5 lib/hyperloop/active_support_string_inquirer.rb
hyperloop-config-0.99.4 lib/hyperloop/active_support_string_inquirer.rb
activesupport-5.1.6.1 lib/active_support/string_inquirer.rb
hyperstack-config-1.0.alpha1.2 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.alpha1.1 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.0.pre.alpha1 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.alpha1 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-1.0.pre.alpha1 lib/hyperstack/active_support_string_inquirer.rb
hyperstack-config-0.1 lib/hyperstack/active_support_string_inquirer.rb
hyperloop-config-0.99.3 lib/hyperloop/active_support_string_inquirer.rb