Ruby1.9.2 looking for Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:312

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

···

--
Posted via http://www.ruby-forum.com/.

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<<....."

···

--
Posted via http://www.ruby-forum.com/.

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

···

On Dec 12, 2010, at 9:20 PM, Guru I. wrote:

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/csv.rb:312:in
`open_reader'
from

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?

···

--
Posted via http://www.ruby-forum.com/.

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

thanks
guru

···

--
Posted via http://www.ruby-forum.com/.