Skip to content

Commit ad57541

Browse files
marcandrematzbot
authored andcommitted
[ruby/ostruct] Avoid aliasing block_given? for JRuby [Fixes #40]
ruby/ostruct@14d04ff694
1 parent 137e69b commit ad57541

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/ostruct.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ def dig(name, *names)
356356
#
357357
# person.delete_field('number') { 8675_309 } # => 8675309
358358
#
359-
def delete_field(name)
359+
def delete_field(name, &block)
360360
sym = name.to_sym
361361
begin
362362
singleton_class.remove_method(sym, "#{sym}=")
363363
rescue NameError
364364
end
365365
@table.delete(sym) do
366-
return yield if block_given!
366+
return yield if block
367367
raise! NameError.new("no field `#{sym}' in #{self}", sym)
368368
end
369369
end
@@ -467,6 +467,11 @@ def init_with(coder) # :nodoc:
467467
end
468468
# Other builtin private methods we use:
469469
alias_method :raise!, :raise
470-
alias_method :block_given!, :block_given?
471-
private :raise!, :block_given!
470+
private :raise!
471+
472+
# See https://github.com/ruby/ostruct/issues/40
473+
if RUBY_ENGINE != 'jruby'
474+
alias_method :block_given!, :block_given?
475+
private :block_given!
476+
end
472477
end

0 commit comments

Comments
 (0)