Skip to content

Commit

Permalink
[ruby/ostruct] Avoid aliasing block_given? for JRuby [Fixes #40]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and matzbot committed Mar 24, 2022
1 parent 137e69b commit ad57541
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,14 @@ def dig(name, *names)
#
# 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
Expand Down Expand Up @@ -467,6 +467,11 @@ def init_with(coder) # :nodoc:
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

0 comments on commit ad57541

Please sign in to comment.