Problem using IRB

Hey,

I could download it and also use IRB. However, I was wondering if you
could tell me how to run this code on IRB:
def fact(n)
  if n == 0
    1
  else
    n * fact(n-1)
  end
end

print fact(ARGV[0].to_i), "\n"

I tried doing it but its running each line separately. Is there any way
to run the whole thing at once.

Thanks,
Vidhi

···

-----Original Message-----
From: Curt Hibbs [mailto:curt@hibbs.com]
Sent: Friday, February 11, 2005 11:15 AM
To: ruby-talk ML
Subject: Re: new to this language

Ghelani, Vidhi wrote:

Hey curt,

No I did'nt install this using the one-click installer. Truly
speaking I don't know how I got this. Neways, I tried 2 things
1) Tried using irb from the secure shell that I am using. I just
typed irb, and it says -bash: -irm: command not found
2) Since I have a windows machine, I tried using the command
prompt window and from there I typed in irb. Hmm...but this Does
not work either !

How do I go about getting irb, cos it sounds really kewl.

Go here:

  http://rubyinstaller.rubyforge.org/

and follow the download link. Download the latest version of the
installer
(182-14). Once you have installed ruby from you should find a number of
use
tools in you start menu under "Ruby", and you should be able to run
"irb"
from the command line to get into an interactive ruby session.

Curt

Hi Vidhi,

You seem to have a lot of questions! You would probably really benefit from buying the book "Programming Ruby" by Dave Thomas. He answers a lot of the questions you're asking, and a lot more besides.

It takes you all the way from the very basic things, the ones you're having some troubles with, all the way to the really advanced stuff.

http://pragmaticprogrammer.com/titles/ruby/

You can buy a paper version, a PDF, or both! I'd recommend both. The paper copy is great for sitting and reading, but you can take the PDF with you, and can search through it easily.

Ben

ARGV = %w| 15 |
load 'factorial.rb'

Hi,

Hey,

I could download it and also use IRB. However, I was wondering if you
could tell me how to run this code on IRB:
def fact(n)
  if n == 0
    1
  else
    n * fact(n-1)
  end
end

print fact(ARGV[0].to_i), "\n"

I tried doing it but its running each line separately. Is there any way
to run the whole thing at once.

I'm not sure why you would need to run it all at once; there's no real
difference in IRB between running the statements separately and
running them all together. Is there any particular reason?

Still, you can do it if you want, by using explicit statement
separators (";") and newline escapes ("\"):

def fact(n)
  if n == 0
    1
  else
    n * fact(n-1)
  end
end;\
\
print fact(ARGV[0].to_i), "\n"

This should run it as one chunk of code in irb. The ;s make sure the
interpreter separates the statements. The \s make sure it doesn't stop
evaluating the code at the newlines

As a side note, ARGV is usually empty in irb, I think.

HTH,
Mark

···

On Sat, 12 Feb 2005 04:56:04 +0900, Ghelani, Vidhi <vidhi.ghelani@intel.com> wrote: