[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to execute ruby file from other ruby file?

szczepiq

1/10/2006 4:12:00 PM

How to execute ruby file from other ruby file?

Thanks!

--
Posted via http://www.ruby-....


4 Answers

Dirk Meijer

1/10/2006 4:15:00 PM

0

require 'filename'

you're welcome


2006/1/10, Szczepan Faber <szczepiq@gmail.com>:
>
> How to execute ruby file from other ruby file?
>
> Thanks!
>
> --
> Posted via http://www.ruby-....
>
>

james_b

1/10/2006 4:29:00 PM

0

Dirk Meijer wrote:
> require 'filename'
>
> you're welcome

Or,

`ruby filename.rb` # back-tics

which will trigger code that is testing to see if the file is called
directly. E.g.:

if __FILE__ == $0
# do me!
end

James
--

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


Ara.T.Howard

1/10/2006 4:31:00 PM

0

David Vallner

1/11/2006 4:36:00 AM

0

Szczepan Faber wrote:

>How to execute ruby file from other ruby file?
>
>Thanks!
>
>
>
To provide a comparison of the previously mentioned approaches:

`ruby foo.rb` creates a completely separate interpreter, which you might
or might not want. You can't directly access anything defined in one
script in the other.

require is more commonly used to load libraries, since it will only
process a file once; On the other side, load will always process the file.

For example, if you have (in the same directory) the files:

1. foo.rb

puts "FOO"

2. bar.rb

puts "BAR"

3. test.rb

require 'foo'
require 'foo'
load 'bar.rb'
load 'bar.rb'

Then, unless I'm very much mistaken, the output will be:

FOO
BAR
BAR


David Vallner