timsuth
4/16/2005 4:52:00 AM
In article <KUt6e.962314$6l.177609@pd7tw2no>, Martin DeMello wrote:
>Tim Sutherland <timsuth@ihug.co.nz> wrote:
>>
>> Detecting thread exit immediately
>> ---------------------------------
>>
>> Martin DeMello was busy developing his fxirb application (a GUI wrapper
>> around IRB), and had some code that started a Thread whenever it needed to
>> launch an IRB session. How could he tell as soon as the Thread had ended?
>>
>> "Is there any way I can have FXIrb pass in `self' to the thread so that it
>> can call methods on it?"
>>
>> He later reported that the helpful people in the #ruby-lang IRC channel
>> had provided him with the solution,
>>
>> @irb = Thread.new(self) {
>> ....
>> self.quit_method
>> }
>
>My bad - I mixed the two methods up when posting:
>
>@irb = Thread.new {
> ...
> self.quit_method # using the fact that the block is a closure with
> # self in scope
>}
>
>and
>
>@irb = Thread.new(self) {|obj|
> ...
> obj.quit_method # explicitly passing in self as a parameter
>}
Thanks, I've updated the website with the the first version.