attr_reader

attr_reader :city.

attr_reader :city defines a getter.

Goal

Read city from a Sale.

class Sale
  attr_reader :city, :units
  def initialize(city, units)
    @city = city
    @units = units
  end
end
row = Sale.new("Nakuru", 4)
puts row.city
puts row.units
class Sale
  attr_accessor :units
  def initialize(units)
    @units = units
  end
end
row = Sale.new(5)
row.units = 6
puts row.units
class Kiosk
  attr_reader :city
  def initialize(city)
    @city = city
  end
end
puts Kiosk.new("Eldoret").city
class Sale
  attr_reader :shillings
  def initialize(units, price)
    @shillings = units * price
  end
end
puts Sale.new(12, 40).shillings