From 7bcf52edc5db0bf554275ae038d7902ef3075339 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 29 Mar 2022 14:50:42 -0500 Subject: [PATCH] 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. --- lib/ostruct.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ostruct.rb b/lib/ostruct.rb index efe5f4f..c5d22dc 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -197,7 +197,7 @@ def to_h(&block) # 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