summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarc-André Lafortune <github@marc-andre.ca>2022-01-29 18:13:45 -0500
committergit <svn-admin@ruby-lang.org>2022-03-24 21:37:14 +0900
commitad5754162bddfd0ce2f11bd7fc7fce90ba6bf7ed (patch)
treee0aabf9209b49293b66dcbbc83930bb111982bb6 /lib
parent137e69b48153dfd47851a1548eeefc6c7c843e92 (diff)
[ruby/ostruct] Avoid aliasing `block_given?` for JRuby [Fixes #40]
https://github.com/ruby/ostruct/commit/14d04ff694
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 8be8704135..258ae436e0 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -356,14 +356,14 @@ class OpenStruct
#
# person.delete_field('number') { 8675_309 } # => 8675309
#
- def delete_field(name)
+ def delete_field(name, &block)
sym = name.to_sym
begin
singleton_class.remove_method(sym, "#{sym}=")
rescue NameError
end
@table.delete(sym) do
- return yield if block_given!
+ return yield if block
raise! NameError.new("no field `#{sym}' in #{self}", sym)
end
end
@@ -467,6 +467,11 @@ class OpenStruct
end
# Other builtin private methods we use:
alias_method :raise!, :raise
- alias_method :block_given!, :block_given?
- private :raise!, :block_given!
+ private :raise!
+
+ # See https://github.com/ruby/ostruct/issues/40
+ if RUBY_ENGINE != 'jruby'
+ alias_method :block_given!, :block_given?
+ private :block_given!
+ end
end