Sha256: f4654fcd7bb5dfda200f166e1e6348e6ae5b83094efd20591c1a417a91aaa087
Contents?: true
Size: 867 Bytes
Versions: 1
Compression:
Stored size: 867 Bytes
Contents
module Ginny # Recursively convert keys in a Hash or Array to symbols. # # See: # - [original code](https://avdi.codes/recursively-symbolize-keys/) # - [array support](https://gist.github.com/neektza/8585746) # # @param arg [Hash,Array] # @return [Hash,Array] def self.symbolize_keys(arg) if arg.is_a?(Hash) arg.inject({}) do |result, (key, value)| new_key = case key when String then key.to_sym() else key end new_value = case value when Hash then symbolize_keys(value) when Array then symbolize_keys(value) else value end result[new_key] = new_value result end elsif arg.is_a?(Array) arg.map { |e| symbolize_keys(e) } else arg end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ginny-0.5.0 | lib/ginny/symbolize.rb |