Sha256: 4e03731a9e9f29b37a1a5075c37c188d4c66e791f71ad56adf6b1782c69077cd
Contents?: true
Size: 1001 Bytes
Versions: 3
Compression:
Stored size: 1001 Bytes
Contents
module Lotus module Utils # Hash on steroids # @since 0.1.0 class Hash < ::Hash # Initialize the hash # # @param hash [::Hash, Hash] the value we want to use to initialize this instance # # @return [Hash] self # # @since 0.1.0 def initialize(hash = {}) merge! hash end # Convert in-place all the keys to Symbol instances, nested hashes are converted too. # # @return [Hash] self # # @since 0.1.0 # # @example # require 'lotus/utils/hash' # # hash = Lotus::Utils::Hash.new 'a' => 23, 'b' => { 'c' => ['x','y','z'] } # hash.symbolize! # # hash.keys # => [:a, :b] # hash.inspect # => {:a=>23, :b=>{:c=>["x", "y", "z"]}} def symbolize! keys.each do |k| v = delete(k) v = Hash.new(v).symbolize! if v.is_a?(::Hash) self[k.to_sym] = v end self end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lotus-utils-0.2.0 | lib/lotus/utils/hash.rb |
lotus-utils-0.1.1 | lib/lotus/utils/hash.rb |
lotus-utils-0.1.0 | lib/lotus/utils/hash.rb |