[ruby/ostruct] Avoid aliasing `block_given?` for JRuby [Fixes #40]

https://github.com/ruby/ostruct/commit/14d04ff694
This commit is contained in:
Marc-André Lafortune 2022-01-29 18:13:45 -05:00 коммит произвёл git
Родитель 137e69b481
Коммит ad5754162b
1 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -356,14 +356,14 @@ class OpenStruct
# #
# person.delete_field('number') { 8675_309 } # => 8675309 # person.delete_field('number') { 8675_309 } # => 8675309
# #
def delete_field(name) def delete_field(name, &block)
sym = name.to_sym sym = name.to_sym
begin begin
singleton_class.remove_method(sym, "#{sym}=") singleton_class.remove_method(sym, "#{sym}=")
rescue NameError rescue NameError
end end
@table.delete(sym) do @table.delete(sym) do
return yield if block_given! return yield if block
raise! NameError.new("no field `#{sym}' in #{self}", sym) raise! NameError.new("no field `#{sym}' in #{self}", sym)
end end
end end
@ -467,6 +467,11 @@ class OpenStruct
end end
# Other builtin private methods we use: # Other builtin private methods we use:
alias_method :raise!, :raise alias_method :raise!, :raise
private :raise!
# See https://github.com/ruby/ostruct/issues/40
if RUBY_ENGINE != 'jruby'
alias_method :block_given!, :block_given? alias_method :block_given!, :block_given?
private :raise!, :block_given! private :block_given!
end
end end