English 中文(简体)
为什么相对需要1.8.6的鲁比工作?
原标题:Why doesn t relative_require work on Ruby 1.8.6?
  • 时间:2010-04-21 07:28:17
  •  标签:
  • ruby
  • require

视窗7的Im学习R.R.(使用版本1.8.6)。

当我尝试实施以下<>strong>stock_stats.rb方案时,我发现以下错误:

C:UsersWillDesktop
uby>ruby stock_stats.rb
stock_stats.rb:1: undefined method `require_relative  for main:Object (NoMethodE
rror)

我有三件“小码”文件:

<>strong>stock_stats.rb

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

csv_reader.rb

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  

  # 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       

book_in_stock.rb

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  

  # 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       

事先得到任何帮助。

最佳回答

<><>Edit>:

在提出这一问题的几天后,它又提到了Ruby 1.8.6,那里没有require_relative。 到现在为止,Ruby 1.8.6已经过时,应该再使用。

www.un.org/Depts/DGACM/index_french.htm

没有任何方法名称<代码>要求_relative。 页: 1 在那里,情况好。

You should be able to install them with gem install extensions. Then in your code add the following line before the require_relative:

require  extensions/all 
问题回答

<代码>查询_relative 页: 1 页: 1 gem and require reports/1.9.1/kernel/require/relative , but the easiest fix will be reflected demand to:

require File.join(File.dirname(__FILE__),  csv_reader )




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签