Finally, you can run a Ruby program from a file as you would any other
shell script, Perl program, or Python program. You can simply run Ruby giving
the script name as an argument:
Or you can use the Unix ``shebang'' notation as the first line of the
program file.
[If your system supports it, you can avoid hard-coding
the path to Ruby in the shebang line by using
#!/usr/bin/env ruby
, which will search your path for ruby
and then execute it.]
#!/usr/local/bin/ruby -w
puts "Hello, World!"
|
If you make this source file executable (using, for instance,
chmod +x myprog.rb
), Unix lets you run the file as a
program:
% ./myprog.rb
Hello, World!
|
You can do something similar under Microsoft Windows using file
associations.