[前][次][番号順一覧][スレッド一覧]

ruby-changes:71578

From: Charles <ko1@a...>
Date: Fri, 1 Apr 2022 00:17:01 +0900 (JST)
Subject: [ruby-changes:71578] 8751769637 (master): [ruby/ostruct] Avoid using block_given in the presence of aliases

https://git.ruby-lang.org/ruby.git/commit/?id=8751769637

From 87517696373cdcf38de2b11d9f2cfbe950e3ef47 Mon Sep 17 00:00:00 2001
From: Charles Oliver Nutter <headius@h...>
Date: Tue, 29 Mar 2022 14:50:42 -0500
Subject: [ruby/ostruct] Avoid using block_given in the presence of aliases

defined?(yield) bypasses the block_given? method (or any aliases
to it) and always does the right thing.

https://github.com/ruby/ostruct/commit/4c38fe612e
---
 lib/ostruct.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index efe5f4fe37..c5d22dc8a2 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -197,7 +197,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L197
   #   data.each_pair.to_a   # => [[:country, "Australia"], [:capital, "Canberra"]]
   #
   def each_pair
-    return to_enum(__method__) { @table.size } unless block_given!
+    return to_enum(__method__) { @table.size } unless defined?(yield)
     @table.each_pair{|p| yield p}
     self
   end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]