Require_relative in ruby 1.9.3 error

I have ruby 1.9.3 with rvm and i have simple program about shop.
I write require_relative and i take error:
https://gist.github.com/maasdesigner/6405171

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

You forgot end :slight_smile:
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 :slight_smile:

Sent from my tablet

On 2013-09-03, at 10:50 PM, Nikodem S. [email protected] wrote:

   end

end

Try it now :slight_smile:

Should add_item and remove_item refer to @items rather than @item ?

Mike

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs