summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkinori MUSHA <[email protected]>2024-09-19 16:09:21 +0900
committergit <[email protected]>2024-09-19 07:11:58 +0000
commite53d2f2092111828d692c85b5f0d0d57be1d095f (patch)
treef5adb3a8d059b6566bd4173bcb01c56545ba9f06
parent24b587e7ba08e9347d4b4f02c6442eac7ccba54c (diff)
[ruby/set] Reword the document for to_a and clarify the implementation notes
ref. https://github.com/ruby/ruby/pull/11453 https://github.com/ruby/set/commit/3cf6d11bd2
-rw-r--r--lib/set.rb16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/set.rb b/lib/set.rb
index a0954a31d1..374c45b19a 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -335,7 +335,7 @@ class Set
end
end
- # Converts the set to an array. The order of elements is uncertain.
+ # Returns an array containing all elements in the set.
#
# Set[1, 2].to_a #=> [1, 2]
# Set[1, 'c', :s].to_a #=> [1, "c", :s]
@@ -540,11 +540,11 @@ class Set
# Deletes every element of the set for which block evaluates to
# true, and returns self. Returns an enumerator if no block is
# given.
- def delete_if
+ def delete_if(&block)
block_given? or return enum_for(__method__) { size }
- # @hash.delete_if should be faster, but using it breaks the order
- # of enumeration in subclasses.
- select { |o| yield o }.each { |o| @hash.delete(o) }
+ # Instead of directly using @hash.delete_if, perform enumeration
+ # using self.each that subclasses may override.
+ select(&block).each { |o| @hash.delete(o) }
self
end
@@ -553,9 +553,9 @@ class Set
# given.
def keep_if
block_given? or return enum_for(__method__) { size }
- # @hash.keep_if should be faster, but using it breaks the order of
- # enumeration in subclasses.
- reject { |o| yield o }.each { |o| @hash.delete(o) }
+ # Instead of directly using @hash.keep_if, perform enumeration
+ # using self.each that subclasses may override.
+ reject(&block).each { |o| @hash.delete(o) }
self
end