Class: Hash

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

Class Method Summary collapse

Class Method Details

.keys_to_strings(obj) ⇒ Hash

Transforms all keys of a hash to strings.

Parameters:

  • the (Hash)

    Hash whose keys to convert.

Returns:

  • (Hash)

    the new Hash with strings as keys.



18
19
20
21
22
# File 'lib/automata.rb', line 18

def self.keys_to_strings(obj)
  return obj unless obj.kind_of? Hash
  obj = obj.inject({}){|h,(k,v)| h[k.to_s] = Hash.keys_to_strings(v); h}
  return obj
end