summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorAkinori MUSHA <[email protected]>2023-02-24 15:58:19 +0900
committergit <[email protected]>2023-02-24 11:48:07 +0000
commit454ac4cbb22fdae44a75cef1412693e4fb526630 (patch)
tree9c684221fe09d1a1cf5b954e73fabcf3ce832578 /lib/set.rb
parentaff41a36693c0274633914afb2cfbdb8169c1cbd (diff)
[ruby/set] Set#merge takes many enumerable objects like Hash#merge! does
https://github.com/ruby/set/commit/becaca994d
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/set.rb b/lib/set.rb
index ff312ee906..9140d024cf 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -152,7 +152,7 @@
# If the given object is not an element in the set,
# adds it and returns +self+; otherwise, returns +nil+.
# - \#merge:
-# Adds each given object to the set; returns +self+.
+# Merges the elements of each given enumerable object to the set; returns +self+.
# - \#replace:
# Replaces the contents of the set with the contents
# of a given enumerable.
@@ -596,13 +596,15 @@ class Set
# Equivalent to Set#select!
alias filter! select!
- # Merges the elements of the given enumerable object to the set and
+ # Merges the elements of the given enumerable objects to the set and
# returns self.
- def merge(enum)
- if enum.instance_of?(self.class)
- @hash.update(enum.instance_variable_get(:@hash))
- else
- do_with_enum(enum) { |o| add(o) }
+ def merge(*enums)
+ enums.each do |enum|
+ if enum.instance_of?(self.class)
+ @hash.update(enum.instance_variable_get(:@hash))
+ else
+ do_with_enum(enum) { |o| add(o) }
+ end
end
self