summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/set.rb b/lib/set.rb
index 5a96c81..e7d1be4 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -464,7 +464,15 @@ class Set
# Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
def &(enum)
n = self.class.new
- do_with_enum(enum) { |o| n.add(o) if include?(o) }
+ if enum.is_a?(Set)
+ if enum.size > size
+ each { |o| n.add(o) if enum.include?(o) }
+ else
+ enum.each { |o| n.add(o) if include?(o) }
+ end
+ else
+ do_with_enum(enum) { |o| n.add(o) if include?(o) }
+ end
n
end
alias intersection &