Sha256: 0b26d7fa8ae1d15dfd9f3fcf426170b57086e9ce2da3d53482589ecd89403378
Contents?: true
Size: 1.12 KB
Versions: 13
Compression:
Stored size: 1.12 KB
Contents
module Hashie2 module Extensions module StringifyKeys # Convert all keys in the hash to strings. # # @example # test = {:abc => 'def'} # test.stringify_keys! # test # => {'abc' => 'def'} def stringify_keys! keys.each do |k| self[k.to_s] = self.delete(k) end self end # Return a new hash with all keys converted # to strings. def stringify_keys dup.stringify_keys! end end module SymbolizeKeys # Convert all keys in the hash to strings. # # @example # test = {'abc' => 'def'} # test.symbolize_keys! # test # => {:abc => 'def'} def symbolize_keys! keys.each do |k| self[k.to_sym] = self.delete(k) end self end # Return a new hash with all keys converted # to symbols. def symbolize_keys dup.symbolize_keys! end end module KeyConversion def self.included(base) base.send :include, SymbolizeKeys base.send :include, StringifyKeys end end end end
Version data entries
13 entries across 13 versions & 1 rubygems