summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-19 00:29:54 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-19 00:29:54 +0000
commita88cc058f00df2df4fc12bc245a936521015b2fe (patch)
tree8ae95ec9695e33639b44f4d41e59e28958fd6104 /lib/set.rb
parent25bccc44d4710f839fb257d21ce2ca59249e4ba0 (diff)
* lib/set.rb: Add checks that passed argument is Enumerable. [ruby-core:23844]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/set.rb b/lib/set.rb
index f21ff14..e28ab0f 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -70,6 +70,7 @@ class Set
enum.nil? and return
if block
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| add(block[o]) }
else
merge(enum)
@@ -122,6 +123,7 @@ class Set
if enum.class == self.class
@hash.replace(enum.instance_eval { @hash })
else
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
clear
enum.each { |o| add(o) }
end
@@ -279,6 +281,7 @@ class Set
if enum.instance_of?(self.class)
@hash.update(enum.instance_variable_get(:@hash))
else
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| add(o) }
end
@@ -288,6 +291,7 @@ class Set
# Deletes every element that appears in the given enumerable object
# and returns self.
def subtract(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| delete(o) }
self
end
@@ -310,6 +314,7 @@ class Set
# Returns a new set containing elements common to the set and the
# given enumerable object.
def &(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
n = self.class.new
enum.each { |o| n.add(o) if include?(o) }
n
@@ -637,6 +642,7 @@ end
# end
#
# def replace(enum)
+# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# clear
# enum.each { |o| add(o) }
#
@@ -644,6 +650,7 @@ end
# end
#
# def merge(enum)
+# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# enum.each { |o| add(o) }
#
# self
@@ -711,10 +718,10 @@ class TC_Set < Test::Unit::TestCase
Set.new([1,2])
Set.new('a'..'c')
}
- assert_raises(NoMethodError) {
+ assert_raises(ArgumentError) {
Set.new(false)
}
- assert_raises(NoMethodError) {
+ assert_raises(ArgumentError) {
Set.new(1)
}
assert_raises(ArgumentError) {