Method: OpenStruct#delete_field

Defined in:
lib/missing/ostruct.rb

#delete_field(name) ⇒ Object

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

require 'ostruct'

person = OpenStruct.new('name' => 'John Smith', 'age' => 70)

person.delete_field('name')  # => 'John Smith'


221
222
223
224
225
# File 'lib/missing/ostruct.rb', line 221

def delete_field(name)
  sym = name.to_sym
  singleton_class.__send__(:remove_method, sym, "#{name}=")
  @table.delete sym
end