delete_field(name) public

Removes the named field from the object. Returns the value that the field contained if it was defined.

require "ostruct"

person = OpenStruct.new(name: "John", age: 70, pension: 300)

person.delete_field("age")   # => 70
person                       # => #<OpenStruct name="John", pension=300>

Setting the value to nil will not remove the attribute:

person.pension = nil
person                 # => #<OpenStruct name="John", pension=nil>
Show source
Register or log in to add new notes.