Sha256: 40f3bea583190a6c49351d12b86f4eda0e76ff2d7172ce2b322aee66170e6628
Contents?: true
Size: 871 Bytes
Versions: 1
Compression:
Stored size: 871 Bytes
Contents
module FoodTruck # 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 |
---|---|
food_truck-0.5.3 | lib/food_truck/symbolize.rb |