class Pushwagner::HashWithIndifferentAccess
Shamefully copied from ActiveSupport
Public Class Methods
new(hash={})
click to toggle source
Calls superclass method
# File lib/pushwagner/ext.rb, line 10 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/pushwagner/ext.rb, line 17 def [](key) super(convert_key(key)) end
[]=(key, value)
click to toggle source
Calls superclass method
# File lib/pushwagner/ext.rb, line 21 def []=(key, value) super(convert_key(key), value) end
delete(key)
click to toggle source
Calls superclass method
# File lib/pushwagner/ext.rb, line 25 def delete(key) super(convert_key(key)) end
merge(other)
click to toggle source
# File lib/pushwagner/ext.rb, line 33 def merge(other) dup.merge!(other) end
merge!(other)
click to toggle source
# File lib/pushwagner/ext.rb, line 37 def merge!(other) other.each do |key, value| self[convert_key(key)] = value end self end
to_hash()
click to toggle source
# File lib/pushwagner/ext.rb, line 44 def to_hash Hash.new(default).merge!(self) end
values_at(*indices)
click to toggle source
# File lib/pushwagner/ext.rb, line 29 def values_at(*indices) indices.collect { |key| self[convert_key(key)] } end
Protected Instance Methods
convert_key(key)
click to toggle source
# File lib/pushwagner/ext.rb, line 49 def convert_key(key) key.is_a?(Symbol) ? key.to_s : key end
method_missing(method, *args, &block)
click to toggle source
# File lib/pushwagner/ext.rb, line 53 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