Neither ruby and nor irb can load .rb file in current directory

前端 未结 7 1135
慢半拍i
慢半拍i 2021-01-31 17:30

I\'m having a really noob problem with importing files in Ruby. I\'m making a Ruby app in Windows XP. All the class files for the app are in \"C:/Documents/Prgm/Surveyor_R

相关标签:
7条回答
  • 2021-01-31 17:46

    I believe both of the previous posts are correct, just for different uses. In IRB use an absolute path with require, with a file you can also use require with an absolute path, or use require_relative.

    0 讨论(0)
  • 2021-01-31 17:51

    If you're trying to do this with rvmsudo, I found this worked for me:

    rvmsudo irb -I '/Absolute/path/to/your/project'
    
    0 讨论(0)
  • 2021-01-31 17:53

    it's damn dirty, but you can always do at the very first line:

    $: << '.'
    

    and off you go with pwd'ed require. It's quite useful for interactive/creative testing with IRB

    0 讨论(0)
  • 2021-01-31 17:55

    None of these worked for me, but this did:

    irb -I .
    >require 'file'
     => true
    
    0 讨论(0)
  • 2021-01-31 18:00

    Noticed the same behavior but my linux roots had me try:.\file.rb and it loaded into the irb. Try explicitly declaring the current directory.

    0 讨论(0)
  • 2021-01-31 18:03
    require './hede'
    

    or

    require_relative 'hede'
    

    This works for me in both Ruby (1.9.3) and JRuby (1.7.x) on linux. I haven't tested it on windows.

    0 讨论(0)
提交回复
热议问题