ruby1.9.2 looking for

G

Guru I.

Hi

I have just started learning ruby and Im using ruby 1.9.2p0 (2010-08-18
revision 29036) [x86_64-darwin10.5.0].

Im trying to run a program from a book for CSV reader and when I try to
run it (using csv file as input) i get error from CSV library which is
under 1.8. And Im not sure if its correct..

Can someone please help

Thanks
guru

Processing sample.csv
/csv_reader.rb:14:in `read_in_csv_data': uninitialized constant
CsvReader::BooksInStock (NameError)
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:312:in
`open_reader'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:532:in
`parse'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:560:in
`each'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:531:in
`parse'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:311:in
`open_reader'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:94:in
`foreach'
from ./csv_reader.rb:13:in `read_in_csv_data'
from ./stock_stats.rb:12
from ./stock_stats.rb:10:in `each'
from ./stock_stats.rb:10
 
G

Guru I.

i came across this forum http://www.ruby-forum.com/topic/206773 but i
still dont get what I have to use. Also I thought it might help to
provide my code here

#!/usr/bin/ruby
require 'csv'
require 'books_v2'
#require_relative 'books_v2'

class CsvReader
def initialize
@books_in_stock = []
end

def read_in_csv_data(cvs_file_name)
CSV.foreach( cvs_file_name, :headers => true ) do |row|
@books_in_stock << BooksInStock.new(row["ISBN"], row["Amount"])
end
end

def total_value_in_stock
sum = 0.0
@books_in_stock.each {|book| sum += book.price}
sum
end
end


And I get error @ line "@book_in_stock<<....."
 
J

James Edward Gray II

I have just started learning ruby and Im using ruby 1.9.2p0 = (2010-08-18
revision 29036) [x86_64-darwin10.5.0].
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/cs=
v.rb:312:in
`open_reader'
from

Something has gotten confused with your Ruby install, because you =
mention version 1.9, but the code is trying to load a 1.8 library.

RVM is probably the best way to manage your Ruby installs on Mac OS X, =
so I recommend you try that:

http://rvm.beginrescueend.com/

Hope that helps.

James Edward Gray II
 
G

Guru I.

Sorry I just cant find the solution and when i checked my ruby
installation 1.9.2 ..

its in /Users/XXXXX/.rvm/bin

XXXX - my home directory

but Why its looking for library under /System/Library/Frameworks...path?
 
G

Guru I.

please ignore my last post as i did not realize it found a reply. I will
look for rvm and get back

thanks
guru
 

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,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top