Module: HashKeys
- Defined in:
- lib/helpers/hash_helpers.rb
Class Method Summary collapse
- .str_to_sym(a_hash) ⇒ Object
-
.sym_to_str(a_hash) ⇒ Object
inverse of above.
Class Method Details
.str_to_sym(a_hash) ⇒ Object
33 34 35 36 |
# File 'lib/helpers/hash_helpers.rb', line 33 def self.str_to_sym(a_hash) raise "#{a_hash.class.name} must respond to inject" unless a_hash.respond_to? :inject a_hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} end |
.sym_to_str(a_hash) ⇒ Object
inverse of above
38 39 40 41 |
# File 'lib/helpers/hash_helpers.rb', line 38 def self.sym_to_str(a_hash) #inverse of above raise "#{a_hash.class.name} must respond to inject" unless a_hash.respond_to? :inject a_hash.inject({}){|memo,(k,v)| memo["#{k}"] = v; memo} end |