[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Extends Thread

Dott. Hellboy

6/27/2006 9:50:00 PM

Hello

i'm moving the first steps on ruby. I'm writing a simple chat server (a
porting from my java project) just for trying.
now i've a doubt about the Thread class, May i extend it?
I'm thinking something like this:

class ServThread < Thread
def initialize(socket)
super
@soc = socket
end
end

But i didn't find any reference about it. Maybe i can't do that.

any suggest?

Thanks

Dott Hellboy

4 Answers

Robert Klemme

6/28/2006 7:50:00 AM

0

Dott. Hellboy wrote:
> Hello
>
> i'm moving the first steps on ruby. I'm writing a simple chat server (a
> porting from my java project) just for trying.
> now i've a doubt about the Thread class, May i extend it?
> I'm thinking something like this:
>
> class ServThread < Thread
> def initialize(socket)
> super
> @soc = socket
> end
> end
>
> But i didn't find any reference about it. Maybe i can't do that.

Sure you can. But threads are used differently in Ruby than in Java.
You always have to supply a block that contains the work to be done -
much the same as if you supply a Runnable in Java. You can of course do
that in the constructor of your subclass but personally I think it's not
worth the effort.

Did you look at those examples for TCPServer in Pickaxe? Those use
threads as well IIRC.

Kind regards

robert

pere.noel

6/28/2006 7:55:00 AM

0

Robert Klemme <bob.news@gmx.net> wrote:

> Did you look at those examples for TCPServer in Pickaxe?

where is Pickaxe, because i need also examples of thread to start
with...
--
une bévue

Robert Klemme

6/28/2006 9:54:00 AM

0

Une bévue wrote:
> Robert Klemme <bob.news@gmx.net> wrote:
>
>> Did you look at those examples for TCPServer in Pickaxe?
>
> where is Pickaxe, because i need also examples of thread to start
> with...

http://www.google.com/search?q=ru...

pere.noel

6/28/2006 10:11:00 AM

0

Robert Klemme <bob.news@gmx.net> wrote:

>
> http://www.google.com/search?q=ru...

obvious, thanks ;-)
--
une bévue