Method: Object#instance_variable_set

Defined in:
lib/source/ruby.rb

#instance_variable_set(name, obj) ⇒ Object

call-seq:

obj.instance_variable_set(sym, object) -> object

Sets the instance variable named by sym to obj. The variable need not exist prior to this call.

class Klass
  def initialize(a)
    @a = a
  end
end

k = Klass.new(99)
k.instance_variable_set(:@a,79)   #=> 79
k.instance_variable_get('@a')     #=> 79

FIX: Incomplete



487
488
489
# File 'lib/source/ruby.rb', line 487

def instance_variable_set(name, obj)
  `this[name.__value__.replace('@','i$')]=obj`
end