Skip to content

Commit

Permalink
Merge pull request #604 from kachick/hash-update
Browse files Browse the repository at this point in the history
Hash#merge!, Hash#update
  • Loading branch information
alex committed Apr 11, 2013
2 parents c684219 + ef92287 commit 47a3a2b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib-topaz/hash.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def ==(other)
end end


def merge!(other, &block) def merge!(other, &block)
raise RuntimeError.new("can't modify frozen #{self.class}") if frozen?
other = other.to_hash unless other.kind_of? Hash other = other.to_hash unless other.kind_of? Hash
if block if block
other.each do |key, val| other.each do |key, val|
Expand All @@ -66,6 +67,7 @@ def merge!(other, &block)
end end
self self
end end
alias update merge!


def merge(other, &block) def merge(other, &block)
dup.merge! other, &block dup.merge! other, &block
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/core/hash/merge_tags.txt
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1 @@
fails:Hash#merge returns subclass instance for subclasses fails:Hash#merge returns subclass instance for subclasses
fails:Hash#merge! checks frozen status before coercing an object with #to_hash
fails:Hash#merge! raises a RuntimeError on a frozen instance that would not be modified
8 changes: 0 additions & 8 deletions spec/tags/core/hash/update_tags.txt

This file was deleted.

0 comments on commit 47a3a2b

Please sign in to comment.