Module: Useful::RubyExtensions::Hash::FromActivesupport::ClassMethods

Defined in:
lib/useful/ruby_extensions/hash.rb

Instance Method Summary collapse

Instance Method Details

#stringify_keys(hash) ⇒ Object

inspired by ActiveSupport::CoreExtensions::Hash::Keys (api.rubyonrails.org/)



129
130
131
132
# File 'lib/useful/ruby_extensions/hash.rb', line 129

def stringify_keys(hash)
  hash.keys.each{ |key| hash[(key.to_s rescue key)] ||= hash.delete(key) }
  hash
end

#symbolize_keys(hash) ⇒ Object

inspired by ActiveSupport::CoreExtensions::Hash::Keys (api.rubyonrails.org/)



135
136
137
138
# File 'lib/useful/ruby_extensions/hash.rb', line 135

def symbolize_keys(hash)
  hash.keys.each{ |key| hash[(key.to_sym rescue key)] ||= hash.delete(key) }
  hash
end