I was recently helping someone learn Ruby. They are using a Mac (which I am not at all familar with). We were going through the Pick-Axe book (1.9) and typing in code (which I know works on PC and Linux) and received some errors. The code is:
require 'csv'
require_relative 'book_in_stock'
class CsvReader
def initialize
@books_in_stock = []
end
def read_in_csv_data(csv_file_name)
CSV.foreach(csv_file_name, headers: true) do |row|
@books_in_stock << BookInStock.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
We received two errors. The first was pointing at
CSV.foreach(csv_file_name, headers: true) do |row|
and stated unexpected : expecting )
The second was in regards to the final end statement and said
unexpected kend expecting #end
All, I can figure is that it is either because it is a Mac or because we weren't running Ruby 1.9 (we couldn't find it to download for the Mac). Although the book is good at indicating which code snippets require 1.9 and this one was not marked.
Thanks everyone for your help
This post has been edited by Merddin: 15 March 2010 - 04:42 PM

New Topic/Question
Reply


MultiQuote



|