Sha256: 0538fed44527ab5a25ed50063efa6be2874e1d622abd2f2f55b0004f23158ae0

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

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|
        self[k.to_s] = self.delete(k)
      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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hashie-0.1.2 lib/hashie/hash_extensions.rb
hashie-0.1.0 lib/hashie/hash_extensions.rb