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 except(*keys)
def except(*keys) dup.tap do |hash| keys.each { |key| hash.delete(convert_key(key)) } end end
def fetch(key, *args)
def fetch(key, *args) super(convert_key(key), *args) 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 key?(key)
def key?(key) super(convert_key(key)) 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)
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) method = method.to_s if method =~ /^(\w+)\?$/ if args.empty? !!self[$1] else self[$1] == args.first end else self[method] end end
def replace(other_hash)
def replace(other_hash) super(other_hash) end
def reverse_merge(other)
def reverse_merge(other) self.class.new(other).merge(self) end
def reverse_merge!(other_hash)
def reverse_merge!(other_hash) replace(reverse_merge(other_hash)) 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