lib/ostruct.rb in ostruct-0.5.3 vs lib/ostruct.rb in ostruct-0.5.4
- old
+ new
@@ -105,11 +105,11 @@
# ending with <code>!</code>.
#
# For all these reasons, consider not using OpenStruct at all.
#
class OpenStruct
- VERSION = "0.5.3"
+ VERSION = "0.5.4"
#
# Creates a new OpenStruct object. By default, the resulting OpenStruct
# object will have no attributes.
#
@@ -354,18 +354,18 @@
#
# person.delete_field('number') # => NameError
#
# 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
InspectKey = :__inspect_key__ # :nodoc:
@@ -465,8 +465,13 @@
new_name = "#{method}!"
alias_method new_name, method
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