Class: Egalite::StringifyHash

Inherits:
Hash show all
Defined in:
lib/egalite/stringify_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#<<, #>>

Class Method Details

.create(values) ⇒ Object



6
7
8
9
10
# File 'lib/egalite/stringify_hash.rb', line 6

def self.create(values)
  hash = self.new
  hash.update(values)
  hash
end

Instance Method Details

#[](k) ⇒ Object



11
12
13
# File 'lib/egalite/stringify_hash.rb', line 11

def [](k)
  super(stringify(k))
end

#[]=(k, v) ⇒ Object



14
15
16
# File 'lib/egalite/stringify_hash.rb', line 14

def []=(k,v)
  super(stringify(k),v)
end

#delete(key) ⇒ Object



50
51
52
# File 'lib/egalite/stringify_hash.rb', line 50

def delete(key)
  super(stringify(key))
end

#dupObject



42
43
44
# File 'lib/egalite/stringify_hash.rb', line 42

def dup
  StringifyHash.create(self)
end

#fetch(key, *extras) ⇒ Object



34
35
36
# File 'lib/egalite/stringify_hash.rb', line 34

def fetch(key, *extras)
  super(stringify(key), *extras)
end

#key?(key) ⇒ Boolean Also known as: include?, has_key?, member?

Returns:

  • (Boolean)


26
27
28
# File 'lib/egalite/stringify_hash.rb', line 26

def key?(key)
  super(stringify(key))
end

#merge(hash) ⇒ Object



46
47
48
# File 'lib/egalite/stringify_hash.rb', line 46

def merge(hash)
  dup.update(hash)
end

#to_hashObject

Convert to a Hash with String keys.



55
56
57
# File 'lib/egalite/stringify_hash.rb', line 55

def to_hash
  Hash.new(default).merge(self)
end

#update(hash) ⇒ Object Also known as: merge!



17
18
19
20
21
22
23
# File 'lib/egalite/stringify_hash.rb', line 17

def update(hash)
  newhash = {}
  hash.each { |k,v|
    newhash[stringify(k)] = v
  }
  super(newhash)
end

#values_at(*indices) ⇒ Object



38
39
40
# File 'lib/egalite/stringify_hash.rb', line 38

def values_at(*indices)
  indices.collect {|key| self[key]}
end