Module: Hashie::Extensions::MethodQuery

### Home Classes Methods

### In Files

- lib/hashie/extensions/method_access.rb

### Methods

- #method_missing
- #respond_to?

### Class/Module Index

Quicksearch

- Hashie
- Hashie::Clash
- Hashie::Clash::ChainError
- Hashie::CoercionError
- Hashie::Dash
- Hashie::Extensions
- Hashie::Extensions::Coercion
- Hashie::Extensions::Coercion::ClassMethods
- Hashie::Extensions::Coercion::InstanceMethods
- Hashie::Extensions::Dash
- Hashie::Extensions::Dash::IndifferentAccess
- Hashie::Extensions::Dash::IndifferentAccess::ClassMethods
- Hashie::Extensions::DeepFetch
- Hashie::Extensions::DeepFetch::UndefinedPathError
- Hashie::Extensions::DeepFind
- Hashie::Extensions::DeepMerge
- Hashie::Extensions::IgnoreUndeclared
- Hashie::Extensions::IndifferentAccess
- Hashie::Extensions::KeyConversion
- Hashie::Extensions::Mash
- Hashie::Extensions::Mash::SafeAssignment
- Hashie::Extensions::MergeInitializer
- Hashie::Extensions::MethodAccess
- Hashie::Extensions::MethodAccessWithOverride
- Hashie::Extensions::MethodOverridingWriter
- Hashie::Extensions::MethodQuery
- Hashie::Extensions::MethodReader
- Hashie::Extensions::MethodWriter
- Hashie::Extensions::Parsers
- Hashie::Extensions::Parsers::YamlErbParser
- Hashie::Extensions::PrettyInspect
- Hashie::Extensions::StringifyKeys
- Hashie::Extensions::StringifyKeys::ClassMethods
- Hashie::Extensions::SymbolizeKeys
- Hashie::Extensions::SymbolizeKeys::ClassMethods
- Hashie::Hash
- Hashie::Mash
- Hashie::Rash
- Hashie::Trash

No matching classes.

# Hashie::Extensions::MethodQuery

MethodQuery gives you the ability to check for the truthiness of a key via method calls. Note that it will return false if the key is set to a non-truthful value, not if the key isn't set at all. Use key? for checking if a key has been set.

MethodQuery will check against both string and symbol names of the method for existing keys. It also patches respond_to to appropriately detect the query methods.

@example

    class MyHash < Hash
      include Hashie::Extensions::MethodQuery
    end

    h = MyHash.new
    h['abc'] = 123
    h.abc? # => true
    h['def'] = nil
    h.def? # => false
    h.hji? # => NoMethodError

### Public Instance Methods

method_missing(name, *args) click to toggle source

    # File lib/hashie/extensions/method_access.rb, line 114
    def method_missing(name, *args)
      if args.empty? && name.to_s =~ /(.*)\?$/ && (key?(Regexp.last_match[1]) || key?(Regexp.last_match[1].to_sym))
        return self[Regexp.last_match[1]] || self[Regexp.last_match[1].to_sym]
      end

      super
    end

respond_to?(name, include_private = false) click to toggle source

    # File lib/hashie/extensions/method_access.rb, line 109
    def respond_to?(name, include_private = false)
      return true if name.to_s =~ /(.*)\?$/ && (key?(Regexp.last_match[1]) || key?(Regexp.last_match[1].to_sym))
      super
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.