Instance variables hold object state that methods can read and update.

Instance Variables

instance_variables.rb
class Counter
  def initialize
    @count = 0
  end

  def add(amount)
    @count += amount
  end

  def count
    @count
  end
end

step = 
counter = Counter.new

counter.add(step)
counter.add(step)

puts "step=#{step}"
puts "count=#{counter.count}"
class Counter
  def initialize
    @count = 0
  end

  def add(amount)
    @count += amount
  end

  def count
    @count
  end
end

step = 
counter = Counter.new

counter.add(step)
counter.add(step)

puts "step=#{step}"
puts "count=#{counter.count}"
class Counter
  def initialize
    @count = 0
  end

  def add(amount)
    @count += amount
  end

  def count
    @count
  end
end

step = 
counter = Counter.new

counter.add(step)
counter.add(step)

puts "step=#{step}"
puts "count=#{counter.count}"
instance variable An instance variable starts with `@` and belongs to one object instance.