class Thor::CoreExt::HashWithIndifferentAccess
:nodoc:
hash.foo? #=> true<br>hash #=> ‘bar’<br>hash #=> ‘bar’
hash = Thor::CoreExt::HashWithIndifferentAccess.new ‘foo’ => ‘bar’, ‘baz’ => ‘bee’, ‘force’ => true
A hash with indifferent access and magic predicates.
:nodoc:
def [](key)
def [](key) super(convert_key(key)) end
def []=(key, value)
def []=(key, value) super(convert_key(key), value) end
def convert_key(key)
def convert_key(key) key.is_a?(Symbol) ? key.to_s : key end
def delete(key)
def delete(key) super(convert_key(key)) end
def initialize(hash = {})
hash.foo? #=> true
hash['foo'] #=> 'bar'
hash[:foo] #=> 'bar'
hash = Thor::CoreExt::HashWithIndifferentAccess.new 'foo' => 'bar', 'baz' => 'bee', 'force' => true
A hash with indifferent access and magic predicates.
:nodoc:
def initialize(hash = {}) super() hash.each do |key, value| self[convert_key(key)] = value end end
def merge(other)
def merge(other) dup.merge!(other) end
def merge!(other)
def merge!(other) other.each do |key, value| self[convert_key(key)] = value end self end
def method_missing(method, *args, &block)
options.test_framework?(:rspec) # => options[:test_framework] == :rspec
options.shebang # => "/usr/lib/local/ruby"
options.force? # => !!options['force']
Magic predicates. For instance:
def method_missing(method, *args, &block) method = method.to_s if method =~ /^(\w+)\?$/ if args.empty? !!self[$1] else self[$1] == args.first end else self[method] end end
def to_hash
def to_hash Hash.new(default).merge!(self) end
def values_at(*indices)
def values_at(*indices) indices.map { |key| self[convert_key(key)] } end