Class: Egalite::StringifyHash
- Defined in:
- lib/egalite/stringify_hash.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #delete(key) ⇒ Object
- #dup ⇒ Object
- #fetch(key, *extras) ⇒ Object
- #key?(key) ⇒ Boolean (also: #include?, #has_key?, #member?)
- #merge(hash) ⇒ Object
-
#to_hash ⇒ Object
Convert to a Hash with String keys.
- #update(hash) ⇒ Object (also: #merge!)
- #values_at(*indices) ⇒ Object
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 |
#dup ⇒ Object
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?
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_hash ⇒ Object
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 |