Re: a newbie. not getting run a script

san wrote last Wednesday, April 12, 2006 1:45 PM:

#i have tried all the methods above but in vain
#line by line commands are being executed but i could not run
#the program
#as a whole

#i have a screenshot of the commands. if you can plese look into it and
#give your comments where i am going wrong. the first lines are same as
#that in the file count.rb

#since i could not upload image in this forum, i have created a blogger

http://santanusasmal.blogspot.com/

you reminded me of my son :slight_smile:

maybe we should start slowly and ask ourselves first: what is a shell?
what is irb? what is a ruby interpreter? what is a ruby program?

irb is an interactive ruby shell, similar to windows command shell.
Unlike windows’s shell however, in irb you enter ruby commands.

windows’s shell does not understand ruby commands. Ergo, to run a ruby
program under windows, you need to invoke a ruby interpreter. There are
two kinds of interpeter in ruby, one is the plain interpreter named
“ruby”, and the other is the ruby shell named “irb”.

anyway, try playing like this…

C:\Documents and Settings\botp>irb -v
irb 0.9.5(05/04/13)

C:\Documents and Settings\botp>ruby -v
ruby 1.8.4 (2005-12-24) [i386-mswin32]

C:\Documents and Settings\botp>type count.rb
5.times {|x| puts “count #{x}”}

C:\Documents and Settings\botp>ruby count.rb
count 0
count 1
count 2
count 3
count 4

C:\Documents and Settings\botp>irb
irb(main):001:0> require “count.rb”
count 0
count 1
count 2
count 3
count 4
=> true
irb(main):002:0> 5.times {|x| puts “count #{x}” }
count 0
count 1
count 2
count 3
count 4
=> 5
irb(main):003:0> 1+1
=> 2
irb(main):004:0> print “hello, world”
hello, world=> nil
irb(main):005:0> system(“ruby count.rb”)
count 0
count 1
count 2
count 3
count 4
=> true
irb(main):006:0> ruby count.rb
=> “count 0\ncount 1\ncount 2\ncount 3\ncount 4\n”
irb(main):007:0> quit

C:\Documents and Settings\botp>

hth.

btw, Pine’s and Slagell’s ruby books are great for beginners.

kind regards -botp

#regards
#santanu