run scipt under irb

B

Ben

It should be simple, but I have not found the answer yet.

How to run File1.rb under irb prompt?

I can run script under DOS prompt:

C:\> ruby File1.rb

But how can I do this under irb prompt:

irb(main):001:0> File1.rb <== did not work
irb(main):001:0> File1 <== did not work

Thanks.

Ben
 
G

greg.rb

File1 should be in the search path....type:

require 'File1'

or

load 'File1.rb'

from ruby central:
8.12 What is the difference between load and require?

load will load and execute a Ruby program (*.rb).

require loads Ruby programs as well, but will also load binary Ruby
extension modules (shared libraries or DLLs). In addition, require
ensures that a feature is never loaded more than once.
 
R

Ross Bamford

It should be simple, but I have not found the answer yet.

How to run File1.rb under irb prompt?

I can run script under DOS prompt:

C:\> ruby File1.rb

But how can I do this under irb prompt:

irb(main):001:0> File1.rb <== did not work
irb(main):001:0> File1 <== did not work

Not sure if this is what you're after, but you can pass a filename to irb
to have it executed line-by-line, e.g.:

irb File1.rb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top