Run a .rb file in the Ruby console.

Solved
Phal -  
 Et si c'était simple -
Hello, since last night I've been working on learning Ruby or at least trying to understand it.
I have been following this tutorial to the letter so far:
http://www.ruby-lang.org/fr/documentation/quickstart/3/

I'm currently at the section: Welcome everyone and everything!
It says that the program starts to grow in size and that it needs to be typed out in a text editor to be executed in the Ruby console.

I've used Notepad and even the special Ruby text editor.
I've saved the file as mentioned: "ri20min.rb" in .rb format.
So far so good, BUT when I type in my console: "ruby ri20min.rb" to execute it, I get:

NameError: undefined local variable or method `ri20min' for main:Object
from (irb):4
from :0

Even though I've done as instructed.
I've tried to move my file to the console level (or rather the other way around I believe) by writing:

C:\Documents and Settings\user\Bureau>ruby ri20min.rb
Or even:

C:\Documents and Settings\user\Bureau>ri20min.rb

But then I get:

SyntaxError: compile error
(irb):5: syntax error, unexpected $undefined, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
C:\Documents and Settings\user\Bureau>ri20min.rb
^
(irb):5: syntax error, unexpected $undefined, expecting $end
C:\Documents and Settings\user\Bureau>ri20min.rb
^
from (irb):5
from :0

That's it, if my explanation isn't clear, please ask me what’s wrong so you can help me understand.

Thank you in advance.
Configuration: Windows XP Safari 532.3

9 answers

  1. kyby
     
    I think I saw where you went wrong. I just spent the whole afternoon trying to demystify this mystery...
    I believe your error is simply in the fact that at the end of your command you wrote > instead of another backslash
    For example, let me explain my problem, which was just opening a simple program using the console...
    I wrote in Scite puts 5+6

    Then I saved it in the Ruby file anywhere, I think that doesn't matter
    I saved it by naming it allo.rb
    Next, I opened my console, initialized it in irb, and typed the path where my file is located on my computer, which was the following
    C:\ruby\ruby-1.9.2-p0\allo.rb
    Then the console displayed
    the answer I had written in the text editor
    11
    Oh yes, after 4 hours of trying, I finally understood. I hope this helps you.
    4
    1. kyby
       
      in response to Phal
      0
  2. .Phal. Posted messages 3 Status Member 3
     
    In reality, I didn't understand your explanation (and no, I didn't get a solution)
    What is the DOS command prompt doing here?
    And which command are you talking about regarding the cd command?
    3
  3. Phal
     
    I’m bumping the topic out of fear of not getting a response…
    0
  4. .Phal. Posted messages 3 Status Member 3
     
    Is there anyone to help me?
    0
  5. .Phal. Posted messages 3 Status Member 3
     
    Is there still no one to help me?
    0
  6. info3
     
    Hello,
    Have you found the answer to your question?
    If not, the method is to open the DOS command prompt, navigate to the folder where you placed your Ruby file (using the cd command), and run ruby yourfilename.rb

    I hope this information has been useful.
    0
  7. bb
     
    The command in the Ruby console of SketchUp is load "yourfile.rb"
    by default your file must be placed in the SketchUp plugin folder.
    0
  8. Axel
     
    I finally found the solution:
    During the installation of Ruby, you need to check the boxes when it asks for the installation path. Otherwise, it won't load the .rb files.

    Then, you need to launch the Ruby command prompt from the Ruby folder in the Start menu.

    Next, run ruby yourfile.rb.

    I hope this solution will work for you.
    0
  9. Fab64990
     
    "I finally found the solution:
    When installing Ruby, you need to check the boxes when it asks for the installation path. Otherwise, it won't load the .rb files.

    Then, you need to launch the Ruby command prompt from the Ruby folder in the start menu.

    Next, run ruby yourfile.rb.

    I hope this solution works for you."

    Axel is right, then all that's left is to know your path on the right in your empty console.
    Then you "ls" to list the documents
    "cd + the path" to go into a folder
    and then to execute the "~.rb" you use the command: "ruby ~.rb"
    0
    1. Et si c'était simple
       
      I had a similar syntax problem. I simply downloaded another text editor: TextMate, which handles the Ruby format better and doesn't add specific formatting. No more error messages!
      0