summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-06 11:28:21 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-06 11:28:21 +0000
commit305be780df86d3bd5f1b93848101b477083452ed (patch)
tree55d8ff069c370778bc67b2fd80c48a327d50ef30 /lib/set.rb
parentf2ff35c83dde349b5b143ca04afb09955760bcaa (diff)
* lib/set.rb (Set#replace): Check if an object given is enumerable
before clearing self. Reported by yui-knk. [GH-675] https://github.com/ruby/ruby/pull/675 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/set.rb b/lib/set.rb
index db57594..f00cfac 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -91,9 +91,9 @@ class Set
def do_with_enum(enum, &block) # :nodoc:
if enum.respond_to?(:each_entry)
- enum.each_entry(&block)
+ enum.each_entry(&block) if block
elsif enum.respond_to?(:each)
- enum.each(&block)
+ enum.each(&block) if block
else
raise ArgumentError, "value must be enumerable"
end
@@ -149,12 +149,12 @@ class Set
def replace(enum)
if enum.instance_of?(self.class)
@hash.replace(enum.instance_variable_get(:@hash))
+ self
else
+ do_with_enum(enum)
clear
merge(enum)
end
-
- self
end
# Converts the set to an array. The order of elements is uncertain.