Sha256: 492301ab7142e17a65c98d79468ccf7abdcf876174495dfd89002c40914fe5ac

Contents?: true

Size: 1.04 KB

Versions: 32

Compression:

Stored size: 1.04 KB

Contents

class Hash

    if !method_defined?( :to_h )
        alias :to_h :to_hash
    end

    # Converts the hash keys to strings.
    #
    # @param    [Boolean]    recursively
    #   Go through the Hash recursively?
    #
    # @return [Hash]
    #   Hash with +self+'s keys recursively converted to strings.
    def my_stringify_keys( recursively = true )
        stringified = {}
        each do |k, v|
            stringified[k.to_s] = (recursively && v.is_a?( Hash ) ?
                v.my_stringify_keys : v)
        end
        stringified
    end

    # Converts the hash keys to symbols.
    #
    # @param    [Boolean]    recursively
    #   Go through the Hash recursively?
    #
    # @return [Hash]
    #   Hash with +self+'s keys recursively converted to symbols.
    def my_symbolize_keys( recursively = true )
        symbolize = {}
        each do |k, v|
            k = k.respond_to?(:to_sym) ? k.to_sym : k

            symbolize[k] = (recursively && v.is_a?( Hash ) ?
                v.my_symbolize_keys : v)
        end
        symbolize
    end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
cuboid-0.2.11 lib/cuboid/ruby/hash.rb
cuboid-0.2.10 lib/cuboid/ruby/hash.rb
cuboid-0.2.9 lib/cuboid/ruby/hash.rb
cuboid-0.2.8 lib/cuboid/ruby/hash.rb
cuboid-0.2.7 lib/cuboid/ruby/hash.rb
cuboid-0.2.6 lib/cuboid/ruby/hash.rb
cuboid-0.2.5 lib/cuboid/ruby/hash.rb
cuboid-0.2.4.2 lib/cuboid/ruby/hash.rb
cuboid-0.2.4.1 lib/cuboid/ruby/hash.rb
cuboid-0.2.4 lib/cuboid/ruby/hash.rb
cuboid-0.2.3 lib/cuboid/ruby/hash.rb
cuboid-0.2.2 lib/cuboid/ruby/hash.rb
cuboid-0.2.1 lib/cuboid/ruby/hash.rb
cuboid-0.2 lib/cuboid/ruby/hash.rb
cuboid-0.1.9.1 lib/cuboid/ruby/hash.rb
cuboid-0.1.9 lib/cuboid/ruby/hash.rb
cuboid-0.1.8 lib/cuboid/ruby/hash.rb
cuboid-0.1.7 lib/cuboid/ruby/hash.rb
cuboid-0.1.6.1 lib/cuboid/ruby/hash.rb
cuboid-0.1.6 lib/cuboid/ruby/hash.rb