Class: Thor::CoreExt::HashWithIndifferentAccess

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/thor/core_ext/hash_with_indifferent_access.rb

Overview

hash.foo? #=> true

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (protected)

Magic predicates. For instance:

options.force?                  # => !!options['force']
options.shebang                 # => "/usr/lib/local/ruby"
options.test_framework?(:rspec) # => options[:test_framework] == :rspec


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/thor/core_ext/hash_with_indifferent_access.rb', line 22

def method_missing(method, *args)
  method = method.to_s
  if method =~ /^(\w+)\?$/
    if args.empty?
      !!self[$1]
    else
      self[$1] == args.first
    end
  else
    self[method]
  end
end