1

Every time I run a program in ruby, I need to prepend the "ruby" command e.g. ruby program_name.rb

Are there any alternatives to avoid this? Like directly writing program_name.rb or just program_name?

P.S. I am working on Windows(7) I have many files and want to run each file separately. Can't make a batch file for each ruby file.

ian
  • 12,003
  • 9
  • 51
  • 107
vikbehal
  • 1,486
  • 3
  • 21
  • 48
  • 3
    have you tried associating the .rb extension with the Ruby executable? See http://windows.microsoft.com/is-IS/windows-vista/Change-which-programs-Windows-uses-by-default – ian Nov 02 '12 at 07:32
  • @Mischa I think it's more likely a duplicate of this http://stackoverflow.com/questions/1422380/how-to-i-launch-a-ruby-script-from-the-command-line-by-just-its-name – ian Nov 02 '12 at 07:33
  • @Iain, yeah, sorry. Can't change it anymore, but that one is more appropriate. – Mischa Nov 02 '12 at 07:34
  • vikbehal, if an answer from the other pages works for you, please let us know and we can close this question as a duplicate. – ian Nov 02 '12 at 08:00
  • Its not working. I read a book, same method is said. Maybe Issue with Win7. Not Sure. – vikbehal Nov 02 '12 at 10:23

2 Answers2

0

You could write a batch file program_name.bat which contains

ruby program_name.rb

and run it.

Erez Rabih
  • 15,562
  • 3
  • 47
  • 64
-1

You can do this on Windows using the following guide:

http://en.wikibooks.org/wiki/Ruby_Programming/Hello_world#Windows

(I still do not recommend Windows for Ruby programming, however)

sevenseacat
  • 24,699
  • 6
  • 63
  • 88
  • Why not on Windows? I have just started learning RUby. Can you also suggest best book/blog for this? – vikbehal Nov 02 '12 at 07:30
  • 2
    I don't want to give out downvotes, but in what way is that helpful to the OP? Especially the last line. – ian Nov 02 '12 at 07:31
  • Actually, the page you link to *does* describe how to do it in Windows (at the bottom). If you change your answer and point your link to the correct part of that page, I can undo my downvote. – Mischa Nov 02 '12 at 07:42
  • I second Mischa's suggestion. – ian Nov 02 '12 at 07:57