[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Newbie Basic Command Interpreter Question in Ruby

Farrel Lifson

1/29/2007 10:44:00 AM

On 29/01/07, Andrea Maschio <andrea.maschio@gmail.com> wrote:
> Hello Folks, i'm a newbie who desires to implement a basic command
> interpreter written in ruby. Let's say i want to start a new Thread who
> listen to user input
>
> p=Thread.new{
> puts "thread started"
> loop do
> a=gets.chomp
>
> exit if (a=="quit\n")
> puts a
> end
>
> }
>
>
> outputs "thread started" and exits
>
> What i'm i doing wrong? Why the tread doesn't continue looping but exits?
> Sorry for the newbie question, i'm just learning ruby.
>
> Thank you very much for answering
>
> Andrea
>

The p thread is started but the main execution thread (which spawned
the p thread) exits the interpreter. You need to add a 'p.join' at the
end which will wait for p to finish before continuing.

Farrel