Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/mash.rb

Direct Known Subclasses

Mash

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject

Returns a duplicate of the current hash with all of the keys converted to strings.



214
215
216
# File 'lib/mash.rb', line 214

def stringify_keys
  dup.stringify_keys!
end

#stringify_keys!Object

Converts all of the keys to strings



219
220
221
222
223
224
225
226
227
# File 'lib/mash.rb', line 219

def stringify_keys!
  keys.each{|k| 
    v = delete(k)
    self[k.to_s] = v
    v.stringify_keys! if v.is_a?(Hash)
    v.each{|p| p.stringify_keys! if p.is_a?(Hash)} if v.is_a?(Array)
  }
  self
end

#to_mashObject

Returns a new Mash initialized from this Hash.



206
207
208
209
210
# File 'lib/mash.rb', line 206

def to_mash
  mash = Mash.new(self)
  mash.default = default
  mash
end