Importing other files to run ruby programs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idealfellow
    New Member
    • Jan 2008
    • 21

    Importing other files to run ruby programs

    Hi all,
    I have 2 files which are placed in two different folders. These folders
    are not under any Classpath & i am using a windows system.

    I have the following snippet of program, which i am stuck with,
    File1:
    ---------------------------------------------------------------------------------
    <rubycode>

    class Test

    puts " This output is from file1 "

    end
    <rubycode>
    ---------------------------------------------------------------------------------
    FILE 2:
    ---------------------------------------------------------------------------------
    <rubycode>

    require "File1"
    puts "This output is from File2"

    <rubycode>
    ---------------------------------------------------------------------------------
    If File 1 is and File 2 are in two different locations, i get the
    following error :
    FILE2.rb:1:in `require': no such file to load -- Test (LoadError)
    from run.rb:1
    If both the files are in same folder ,it works but if they are located
    in different locations it fails,
    How can make it work, should i provide anything under "require"
    Hope this is clear!!

    Thanks in Advance
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    Include the file path in the require statement.
    [CODE=ruby]require '.../classes/file'[/CODE]
    As a helpful note, you can use code tags when posting by clicking the # button. This inserts code tags which displays the code neatly and saves you some typing. See code tags for more info.

    Comment

    • idealfellow
      New Member
      • Jan 2008
      • 21

      #3
      Originally posted by improvcornartis t
      Include the file path in the require statement.
      [CODE=ruby]require '.../classes/file'[/CODE]
      As a helpful note, you can use code tags when posting by clicking the # button. This inserts code tags which displays the code neatly and saves you some typing. See code tags for more info.
      Thanks for your suggestions, I figured out that giving the following will work!!
      require 'C:\Documents and Settings\Deskto p\File1'
      But what i am looking for is not hardcoding the path, since if someone else has to run my program he should be able to do it without touching in the code like modifying the path name etc..
      I am using eclipse with RDT plugin, is there anyway i can setup these paths!!
      Similar to Build Path for JAVA in eclipse, where in can specify the classpath variables and so on.
      Please let me know if any other workaround for this.

      Cheers

      Comment

      Working...