Rafa_F
1
I have ruby 1.9.3 with rvm and i have simple program about shop.
I write require_relative and i take error:
init.rb
require_relative “cart.rb”
require_relative “item.rb”
item.rb
class Item
def initialize(options)
@price = options[:price]
@weight = options[:weight]
end
attr_reader :price, :weight
attr_writer :price, :weight
end
puts Item.new({:price => 30}).price
cart.rb
class Cart
attr_reader :items
def initialize
@items = Array.new
end
def add_item(item)
@item.push item
end
def remove_item
@item.pop
end
maas_g
2
You forgot end
class Cart
attr_reader :items
def initialize
@items = Array.new
end
def add_item(item)
@item.push item
end
def remove_item
@item.pop
end
end
Try it now
maas_g
3
Sent from my tablet
On 2013-09-03, at 10:50 PM, Nikodem S. [email protected] wrote:
end
end
Try it now
Should add_item and remove_item refer to @items rather than @item ?
Mike