Module: Wahashie::HashExtensions

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/wahashie/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 |wahashie_method|
    base.send :alias_method, wahashie_method, "wahashie_#{wahashie_method}" unless base.instance_methods.include?(wahashie_method)
  end
end

Instance Method Details

#to_mashObject

Convert this hash into a Mash



29
30
31
# File 'lib/wahashie/hash_extensions.rb', line 29

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

#wahashie_stringify_keysObject

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



24
25
26
# File 'lib/wahashie/hash_extensions.rb', line 24

def wahashie_stringify_keys
  self.dup.stringify_keys!
end

#wahashie_stringify_keys!Object

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



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

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