summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <[email protected]>2021-06-14 10:07:51 -0400
committerMarc-AndrĂ© Lafortune <[email protected]>2021-06-14 12:28:53 -0400
commit52369fc545c458efb2fa7e8ca183b119252bb4f9 (patch)
treed05e0b3390418dec40eba25faeede580fe862f59 /lib/ostruct.rb
parentfc98602ecc0cfbf6bb0fb5925298330a1ab227e0 (diff)
[lib/ostruct] Allow overriding of `block_given?`
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4572
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r--lib/ostruct.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index a4e7b446db..eef1d5c861 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -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 block_given!
@table.each_pair{|p| yield p}
self
end
@@ -354,7 +354,7 @@ class OpenStruct
rescue NameError
end
@table.delete(sym) do
- return yield if block_given?
+ return yield if block_given!
raise! NameError.new("no field `#{sym}' in #{self}", sym)
end
end
@@ -453,5 +453,6 @@ class OpenStruct
end
# Other builtin private methods we use:
alias_method :raise!, :raise
- private :raise!
+ alias_method :block_given!, :block_given?
+ private :raise!, :block_given!
end