Need help to run my first program

hi all,
I’m new to ruby and i installed ruby 1.8.7 but I don’t know how to run
it.

should I run my first program on “interactive Ruby” or " start command
prombt with ruby"

please i need the steps to run any program knowing that my operating
system is windows xp.

Thanks a lot in advance

On Tue, Aug 9, 2011 at 12:06 PM, eman a. [email protected]
wrote:

should I run my first program on “interactive Ruby” or " start command
prombt with ruby"

Interactive Ruby (better known as “irb”) is a special Ruby prompt,
which allows you to input Ruby code, and have it “run” immediately.
While you can use it to run scripts and applications, it’s a bin
cumbersome. So, better to use the Command Prompt with Ruby.

Unless Ruby is in your PATH (if you didn’t change any default settings
in the RubyInstaller, it isn’t, however), where any command prompt
will work.


Phillip G.

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz

ok. but I need to open the .rb file an write code in it and then run it
so how can i do it?

On Tue, Aug 9, 2011 at 12:17 PM, eman a. [email protected]
wrote:

ok. but I need to open the .rb file an write code in it and then run it
so how can i do it?

A text editor would be the obvious solution. SciTE[0] is a popular
choice in that area.

It can execute Ruby code, too, but you’ll probably have to set that up
within SciTE. Its documentation will explain how to do that, and it is
likely that a search engine will provide specifics for Ruby.

[0] Scintilla and SciTE


Phillip G.

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz

but what about the code which written in the interactive ruby.
is that write in the one file .rb if yes, how can i find it.

and if i need to write .rb file containing some code and need to run it
uding my installion to ruby 1.8.7. what can i do?

On Tue, Aug 9, 2011 at 12:35 PM, eman a. [email protected]
wrote:

but what about the code which written in the interactive ruby.
is that write in the one file .rb if yes, how can i find it.

No, it’s not stored anywhere, except the .irb-history (if enabled),
which is in your user profile’s root directory. %USERPROFILE% in the
Explorer address bar will take you there.

and if i need to write .rb file containing some code and need to run it
uding my installion to ruby 1.8.7. what can i do?

See my email about SciTE.


Phillip G.

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz

eman a. wrote in post #1015678:

but what about the code which written in the interactive ruby.
is that write in the one file .rb if yes, how can i find it.

and if i need to write .rb file containing some code and need to run it
uding my installion to ruby 1.8.7. what can i do?

They’re two different ways to run code.

(1) Start irb. Type in Ruby expressions. They are executed immediately

$ irb
irb(main):001:0> 2 + 3
=> 5
irb(main):002:0> 3.times { puts “hello” }
hello
hello
hello
=> 3

This is the best way for experimenting with Ruby or testing out some
feature you’ve just learned, as if there’s an error you can just hit
cursor-up and edit/rerun the line.

(2) Open a text editor (even notepad will do), write some ruby in it.
Save it, with extension .rb. Then run it

$ ruby myprog.rb

This will run all the code in the file. This is the best way to write a
larger program.