[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
This commit is contained in:
Charles Oliver Nutter 2022-03-29 14:50:42 -05:00 committed by git
parent af2ab0dd1c
commit 8751769637

View File

@ -197,7 +197,7 @@ class OpenStruct
# 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