Why doesn't relative_require work on Ruby 1.8.6?

后端 未结 2 764
猫巷女王i
猫巷女王i 2020-12-16 13:29

I\'m learning Ruby (using version 1.8.6) on Windows 7.

When I try to run the stock_stats.rb program below, I get the following error:



        
相关标签:
2条回答
  • 2020-12-16 13:57

    require_relative doesn't exist in your version of Ruby. You could upgrade Ruby, install the backports gem and require 'backports/1.9.1/kernel/require/relative' but the easiest fix will be to change your require to:

    require File.join(File.dirname(__FILE__), 'csv_reader')
    
    0 讨论(0)
  • 2020-12-16 14:09

    Edit:

    Back in the days where this question was asked it referred to Ruby 1.8.6 where there was no require_relative. By now Ruby 1.8.6 is outdated and shouldn't be used anymore.

    Original:

    There is simply no method name require_relative. You can use require there aswell.

    The require_relative function is included in an extension project to the Ruby core libraries, found here: http://www.rubyforge.org/projects/extensions

    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'
    
    0 讨论(0)
提交回复
热议问题