require_relative in ruby 1.9.3 error

Discussion in 'Ruby' started by maasgultekin, Sep 1, 2013.

  1. maasgultekin

    maasgultekin Guest

    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
     
    maasgultekin, Sep 1, 2013
    #1
    1. Advertisements

  2. Maybe to simple and obvious, but have you tried `require_relative
    "cart"` (no .rb extension) I think require_relative expects just the
    basename of the file with out an exstension.

     
    DON Who is a ghost, Sep 22, 2013
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.