Module: Hashie::HashExtensions

Included in:
Hash
Defined in:
lib/hashie/hash_extensions.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)



3
4
5
6
7
8
9
# File 'lib/hashie/hash_extensions.rb', line 3

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

Instance Method Details

- (Object) hashie_stringify_keys

Convert all of the keys of a Hash to their string representations.



22
23
24
# File 'lib/hashie/hash_extensions.rb', line 22

def hashie_stringify_keys
  dup.stringify_keys!
end

- (Object) hashie_stringify_keys!

Destructively convert all of the keys of a Hash to their string representations.



13
14
15
16
17
18
# File 'lib/hashie/hash_extensions.rb', line 13

def hashie_stringify_keys!
  keys.each do |k|
    self[k.to_s] = delete(k) unless String === k
  end
  self
end

- (Object) to_mash

Convert this hash into a Mash



27
28
29
# File 'lib/hashie/hash_extensions.rb', line 27

def to_mash
  ::Hashie::Mash.new(self)
end