Skip to content

Commit

Permalink
Avoid using block_given in the presence of aliases
Browse files Browse the repository at this point in the history
defined?(yield) bypasses the block_given? method (or any aliases
to it) and always does the right thing.
  • Loading branch information
headius authored and marcandre committed Mar 31, 2022
1 parent 48d7154 commit 4c38fe6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ostruct.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4c38fe6

Please sign in to comment.