Sha256: fae1e2431712b47d2e3bbb42a46556bf27651a63a7efdba4dbdae37db6c782aa

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

module Hashie
  module HashExtensions
    def self.included(base)
      # Don't tread on existing extensions of Hash by
      # adding methods that are likely to exist.
      %w(stringify_keys stringify_keys!).each do |hashie_method|
        base.send :alias_method, hashie_method, "hashie_#{hashie_method}" unless base.instance_methods.include?(hashie_method)
      end
    end

    # Destructively convert all of the keys of a Hash
    # to their string representations.
    def hashie_stringify_keys!
      self.keys.each do |k|
        unless String === k
          self[k.to_s] = self.delete(k)
        end
      end
      self
    end

    # Convert all of the keys of a Hash
    # to their string representations.
    def hashie_stringify_keys
      self.dup.stringify_keys!
    end

    # Convert this hash into a Mash
    def to_mash
      ::Hashie::Mash.new(self)
    end
  end

  module PrettyInspect
    def self.included(base)
      base.send :alias_method, :hash_inspect, :inspect
      base.send :alias_method, :inspect, :hashie_inspect
    end

    def hashie_inspect
      ret = "#<#{self.class.to_s}"
      stringify_keys.keys.sort.each do |key|
        ret << " #{key}=#{self[key].inspect}"
      end
      ret << ">"
      ret
    end
  end
end

Version data entries

26 entries across 24 versions & 7 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.2 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
climine-0.0.1 vendor/bundle/ruby/2.0.0/gems/hashie-2.0.5/lib/hashie/hash_extensions.rb
hashie-2.0.5 lib/hashie/hash_extensions.rb
hashie-2.0.4 lib/hashie/hash_extensions.rb
hashie-2.0.3 lib/hashie/hash_extensions.rb
hashie-2.0.2 lib/hashie/hash_extensions.rb
hashie-2.0.1 lib/hashie/hash_extensions.rb
hashie-2.0.0 lib/hashie/hash_extensions.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/hashie-1.2.0/lib/hashie/hash_extensions.rb
cb_hashie-2.0.0.beta lib/hashie/hash_extensions.rb
hashie-pre-2.0.0.beta lib/hashie/hash_extensions.rb
hashie-model-1.2.3 vendor/hashie/lib/hashie/hash_extensions.rb