Forum: Ruby require_relative in ruby 1.9.3 error

A1b8f476a5d29f68b06a4d4ff4591bbc?d=identicon&s=25 maas g. (maas_g)
on 2013-09-01 17:38
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
3c04a326a4183d2423e30d68d996dfd6?d=identicon&s=25 Nikodem Solarz (narzew)
on 2013-09-03 23:50
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 :)
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2013-09-04 00:29
(Received via mailing list)
Sent from my tablet

On 2013-09-03, at 10:50 PM, Nikodem Solarz <lists@ruby-forum.com> wrote:

>
>        end
> end
>
> Try it now :)

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

Mike
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.