summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Neighman <has.sox@gmail.com>2009-11-13 23:21:47 +1100
committerDaniel Neighman <has.sox@gmail.com>2009-11-13 23:21:47 +1100
commit39f02086229ab9d024d103840e971381aa57c8e0 (patch)
tree65b83826e54d887249f0e1ecceba8d021ce7a13c
parent91dbf4b1ce807b0529b1ea89a4c5dee5507fdb04 (diff)
downloadhashie-39f02086229ab9d024d103840e971381aa57c8e0.tar.gz
Simplifies the Mash
-rw-r--r--lib/hashie/hash_extensions.rb4
-rw-r--r--lib/hashie/mash.rb26
2 files changed, 5 insertions, 25 deletions
diff --git a/lib/hashie/hash_extensions.rb b/lib/hashie/hash_extensions.rb
index 8fb5657..67d73f6 100644
--- a/lib/hashie/hash_extensions.rb
+++ b/lib/hashie/hash_extensions.rb
@@ -12,7 +12,9 @@ module Hashie
# to their string representations.
def hashie_stringify_keys!
self.keys.each do |k|
- self[k.to_s] = self.delete(k)
+ unless String === k
+ self[k.to_s] = self.delete(k)
+ end
end
self
end
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index 3add1ae..d185a48 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -102,34 +102,12 @@ module Hashie
# in hash, merging each hash in the hierarchy.
def deep_update(other_hash)
other_hash.each_pair do |k,v|
- ck = convert_key(k)
- if Mash === v && Hash === other_hash
- regular_writer(ck, v.deep_merge(other_hash[k]))
- else
- regular_writer(ck, convert_value(other_hash[k], true))
- end
+ regular_writer(convert_key(k), convert_value(other_hash[k], true))
end
self
end
alias_method :deep_merge!, :deep_update
-
- # ==== Parameters
- # other_hash<Hash>::
- # A hash to update values in the mash with. Keys will be
- # stringified and Hashes will be converted to Mashes.
- #
- # ==== Returns
- # Mash:: The updated mash.
- def update(other_hash)
- other_hash.each_pair do |key, value|
- if respond_to?(convert_key(key) + "=")
- self.send(convert_key(key) + "=", convert_value(value))
- else
- regular_writer(convert_key(key), convert_value(value))
- end
- end
- self
- end
+ alias_method :update, :deep_update
alias_method :merge!, :update
# Converts a mash back to a hash (with stringified keys)