Skip to content

Commit 4c38fe6

Browse files
headiusmarcandre
authored andcommitted
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.
1 parent 48d7154 commit 4c38fe6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/ostruct.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def to_h(&block)
197197
# data.each_pair.to_a # => [[:country, "Australia"], [:capital, "Canberra"]]
198198
#
199199
def each_pair
200-
return to_enum(__method__) { @table.size } unless block_given!
200+
return to_enum(__method__) { @table.size } unless defined?(yield)
201201
@table.each_pair{|p| yield p}
202202
self
203203
end

0 commit comments

Comments
 (0)