Class: Thor::Options::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/thor/lib/thor/options.rb

Overview

simple Hash with indifferent access

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Hash

Returns a new instance of Hash.



10
11
12
13
# File 'lib/thor/lib/thor/options.rb', line 10

def initialize(hash)
  super()
  update hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Magic predicates. For instance:

options.force? # => !!options['force']


30
31
32
33
34
35
36
37
38
39
# File 'lib/thor/lib/thor/options.rb', line 30

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

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/thor/lib/thor/options.rb', line 15

def [](key)
  super convert_key(key)
end

#values_at(*indices) ⇒ Object



19
20
21
# File 'lib/thor/lib/thor/options.rb', line 19

def values_at(*indices)
  indices.collect { |key| self[convert_key(key)] }
end