Class: Thor::Options::Hash

Inherits:
Hash
  • Object
show all
Defined in:
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/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
# File 'lib/thor/options.rb', line 30

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

Instance Method Details

#[](key) ⇒ Object



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

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

#values_at(*indices) ⇒ Object



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

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