require_relative in ruby 1.9.3 error

M

maasgultekin

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
 
D

DON Who is a ghost

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.

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top