class Figgy::Hash
Stolen from Thor::CoreExt::HashWithIndifferentAccess It's smaller and more grokkable than ActiveSupport's.
Public Class Methods
new(hash = {})
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 5 def initialize(hash = {}) super() hash.each do |key, value| self[convert_key(key)] = value end end
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 12 def [](key) super(convert_key(key)) end
[]=(key, value)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 16 def []=(key, value) super(convert_key(key), value) end
delete(key)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 24 def delete(key) super(convert_key(key)) end
dig(*keys)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 43 def dig(*keys) super(*keys.map { |k| convert_key(k) }) end
fetch(key, *extras)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 20 def fetch(key, *extras) super(convert_key(key), *extras) end
merge(other)
click to toggle source
# File lib/figgy/hash.rb, line 32 def merge(other) dup.merge!(other) end
merge!(other)
click to toggle source
# File lib/figgy/hash.rb, line 36 def merge!(other) other.each do |key, value| self[convert_key(key)] = value end self end
respond_to?(m, *)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 47 def respond_to?(m, *) super || key?(convert_key(m)) end
respond_to_missing?(m, *)
click to toggle source
Calls superclass method
# File lib/figgy/hash.rb, line 51 def respond_to_missing?(m, *) key?(convert_key(m)) || super end
values_at(*indices)
click to toggle source
# File lib/figgy/hash.rb, line 28 def values_at(*indices) indices.collect { |key| self[convert_key(key)] } end
Protected Instance Methods
convert_key(key)
click to toggle source
# File lib/figgy/hash.rb, line 57 def convert_key(key) key.is_a?(Symbol) ? key.to_s : key end
method_missing(m, *args, &block)
click to toggle source
# File lib/figgy/hash.rb, line 61 def method_missing(m, *args, &block) if m.to_s.end_with? "=" self[m.to_s.chop] = args.shift else self[m] end end