From: 7stud -- Date: 2007-10-01T00:13:09+09:00 Subject: Re: Subclassing Thread? Stephen Ware wrote: > > Those familiar with threading in Java will know that you can write a > class that is a subclass of Thread, and then put the thread's code into > 'public static void run,' which gets executed once thread.start is > called. Can something similar to this be done in Ruby? > The following simulates calling run to start a thread. It stops the thread as soon as it starts, and then restarts the thread when needed: class MyThread < Thread def initialize(x, y) super(x, y) do |val1, val2| Thread.stop puts "In thread..." puts val1, val2 puts end end end t = MyThread.new("hello", "world") puts "main program" puts sleep(2) t.run t.join sleep(2) puts "main program ending..." -- Posted via http://www.ruby-forum.com/.