Method: Object#instance_variable_get

Defined in:
lib/source/ruby.rb

#instance_variable_get(name) ⇒ Object

call-seq:

obj.instance_variable_get(sym) -> object

Returns the value of the given instance variable, or nil if the instance variable is not set. The @ part of the variable name should be included for regular instance variables.

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

k = Klass.new(99)
k.instance_variable_get(:@a)    #=> 99


465
466
467
468
# File 'lib/source/ruby.rb', line 465

def instance_variable_get(name)
  `var v=this[name.__value__.replace('@','i$')]`
  `v==null?nil:v`
end