Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Object#remove_instance_variable

obj.remove_instance_variable(symbol) → obj
obj.remove_instance_variable(string) → obj

Removes the named instance variable from obj, returning that variable’s value. String arguments are converted to symbols.

Example
class Dummy
  attr_reader :var
  def initialize
    @var = 99
  end
  def remove
    remove_instance_variable(:@var)
  end
end
d = Dummy.new
d.var      #=> 99
d.remove   #=> 99
d.var      #=> nil