From e53d2f2092111828d692c85b5f0d0d57be1d095f Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Thu, 19 Sep 2024 16:09:21 +0900 Subject: [PATCH] [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 --- lib/set.rb | 16 ++++++++-------- 1 file 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