C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>type HelloWorld.rb #5.times { print “Odelay!” }
def fact(n)
if n <= 1
1
else
n * fact(n - 1)
end
print n
end
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>HelloWorld.rb
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>HelloWorld.rb
1C:/Documents and Settings/nsaunders/Desktop/HelloWorld.rb:10:in *': nil can't be coerced into Fixnum (TypeError) from C:/Documents and Settings/nsaunders/Desktop/HelloWorld.rb: 10:infa
ct’
from C:/Documents and Settings/nsaunders/Desktop/HelloWorld.rb:
10:in `fa
ct’
from C:/Documents and Settings/nsaunders/Desktop/HelloWorld.rb:
17
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>
Does there need to be class defined to call the method?
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>type HelloWorld.rb #5.times { print “Odelay!” }
n=5
def fact(n)
if n <= 1
1
else
n * fact(n - 1)
end
end
print fact(20)
def hello(i, aString)
i.times {print "\n" + aString + "\n"}
end
hello(6, “success”)
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>HelloWorld.rb
2432902008176640000
success
success
success
success
success
success
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>
Once I took the plunge, it’s quick progress so far! I can change a
line, then just run it. I haven’t gotten used to the idea of the irb,
for now just going back and forth between the DOS prompt and notepad
works smoothly.
I don’t know what the OP is doing wrong (from the source, he isn’t
calling
fact() ever. However, defining a method without a class really defines
it as
part of Kernel (which methods can be called without Classname.method).
line, then just run it. I haven’t gotten used to the idea of the irb,
for now just going back and forth between the DOS prompt and notepad
works smoothly.
There’s nothing wrong with that. I never use irb (or interactive
sessions in other languages I program in). I find them unwieldy and too
much of a hassle to bother with.
If notepad doesn’t provide automatic indenting, then you should try to
obtain a text editor that does. It makes typing in code much easier.
The way it works is that when you hit return and the next line should be
indented, the text editor automatically indents the cursor on the next
line–you don’t have to type any spaces. Likewise, if you type in a
line of code that is indented, and the next line shouldn’t be indented,
then the text editor automatically dedents the next line.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.