Extends Thread

D

Dott. Hellboy

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
 
R

Robert Klemme

Dott. Hellboy said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top