class Hash::WithIndifferentAccess

Stolen from rails

Public Class Methods

new(arg = {}) click to toggle source
Calls superclass method
# File lib/olelo/extensions.rb, line 57
def initialize(arg = {})
  if Hash === arg
    super()
    update(arg)
  else
    super(arg)
  end
end

Public Instance Methods

[]=(key, value) click to toggle source
# File lib/olelo/extensions.rb, line 78
def []=(key, value)
  regular_writer(convert_key(key), value)
  value
end
Also aliased as: regular_writer
default(key = nil) click to toggle source
Calls superclass method
# File lib/olelo/extensions.rb, line 70
def default(key = nil)
  if Symbol === key && regular_include(key = key.to_s)
    self[key]
  else
    super
  end
end
delete(key) click to toggle source
Calls superclass method
# File lib/olelo/extensions.rb, line 114
def delete(key)
  super(convert_key(key))
end
dup() click to toggle source
# File lib/olelo/extensions.rb, line 106
def dup
  WithIndifferentAccess.new(self)
end
fetch(key, *extras) click to toggle source
Calls superclass method
# File lib/olelo/extensions.rb, line 98
def fetch(key, *extras)
  super(convert_key(key), *extras)
end
has_key?(key)
Alias for: key?
include?(key)
Also aliased as: regular_include
Alias for: key?
key?(key) click to toggle source
Calls superclass method
# File lib/olelo/extensions.rb, line 90
def key?(key)
  super(convert_key(key))
end
Also aliased as: include?, has_key?, member?
member?(key)
Alias for: key?
merge(hash) click to toggle source
# File lib/olelo/extensions.rb, line 110
def merge(hash)
  self.dup.update(hash)
end
merge!(other)
Alias for: update
regular_include(key)
Alias for: include?
regular_update(other)
Alias for: update
regular_writer(key, value)
Alias for: []=
to_hash() click to toggle source
# File lib/olelo/extensions.rb, line 118
def to_hash
  Hash.new(default).merge(self)
end
update(other) click to toggle source
# File lib/olelo/extensions.rb, line 83
def update(other)
  other.each_pair {|key, value| regular_writer(convert_key(key), value) }
  self
end
Also aliased as: regular_update, merge!
values_at(*indices) click to toggle source
# File lib/olelo/extensions.rb, line 102
def values_at(*indices)
  indices.collect {|key| self[convert_key(key)]}
end

Protected Instance Methods

convert_key(key) click to toggle source
# File lib/olelo/extensions.rb, line 124
def convert_key(key)
  Symbol === key ? key.to_s : key
end