Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't relative_require work on Ruby 1.8.6?
    text
    copied!<p>I'm learning Ruby (using version 1.8.6) on Windows 7.</p> <p>When I try to run the <strong>stock_stats.rb</strong> program below, I get the following error:</p> <pre><code>C:\Users\Will\Desktop\ruby&gt;ruby stock_stats.rb stock_stats.rb:1: undefined method `require_relative' for main:Object (NoMethodE rror) </code></pre> <p>I have three v.small code files:</p> <p><strong>stock_stats.rb</strong></p> <pre><code>require_relative 'csv_reader' reader = CsvReader.new ARGV.each do |csv_file_name| STDERR.puts "Processing #{csv_file_name}" reader.read_in_csv_data(csv_file_name) end puts "Total value = #{reader.total_value_in_stock}" </code></pre> <p><strong>csv_reader.rb</strong></p> <pre><code>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 &lt;&lt; BookInStock.new(row["ISBN"], row["Amount"]) end end # later we'll see how to use inject to sum a collection def total_value_in_stock sum = 0.0 @books_in_stock.each {|book| sum += book.price} sum end def number_of_each_isbn # ... end end </code></pre> <p><strong>book_in_stock.rb</strong></p> <pre><code>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 &lt;&lt; BookInStock.new(row["ISBN"], row["Amount"]) end end # later we'll see how to use inject to sum a collection def total_value_in_stock sum = 0.0 @books_in_stock.each {|book| sum += book.price} sum end def number_of_each_isbn # ... end end </code></pre> <p>Thanks in advance for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload