[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Catch ^c/signals? blocks?

Elite Force

7/17/2006 9:44:00 AM

Hello,

I'm kinda new to ruby and have a few questions.

If i run a ruby script it can be interrupted with ^c or signals (e.g.
killall ruby"). Is it possible to catch those to do cleanup stuff before
exiting?

Whats the difference between { ... } and do ... end? Are they both
blocks? When to use what?

I'd really appreciate it if you could answer my questions, thanks.

--
Posted via http://www.ruby-....

7 Answers

Ola Bini

7/17/2006 9:51:00 AM

0

Elite Force wrote:
> Hello,
>
> I'm kinda new to ruby and have a few questions.
>
> If i run a ruby script it can be interrupted with ^c or signals (e.g.
> killall ruby"). Is it possible to catch those to do cleanup stuff before
> exiting?
>
> Whats the difference between { ... } and do ... end? Are they both
> blocks? When to use what?
>
> I'd really appreciate it if you could answer my questions, thanks.
>

I would recommend that you lookup either the method Kernel#trap, the
class Signal, or maybe both?

--
Ola Bini (http://ola-bini.bl...)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http:/...)
OLogix Consulting (http://www....)

"Yields falsehood when quined" yields falsehood when quined.



Elite Force

7/17/2006 10:09:00 AM

0

Ola Bini wrote:
> Elite Force wrote:
>>
>> I'd really appreciate it if you could answer my questions, thanks.
>>
>
> I would recommend that you lookup either the method Kernel#trap, the
> class Signal, or maybe both?
>
> --
> Ola Bini (http://ola-bini.bl...)
> JvYAML, RbYAML, JRuby and Jatha contributor
> System Developer, Karolinska Institutet (http:/...)
> OLogix Consulting (http://www....)
>
> "Yields falsehood when quined" yields falsehood when quined.

does ctrl-c also send a signal to the process? (i guess so)

--
Posted via http://www.ruby-....

Ola Bini

7/17/2006 10:32:00 AM

0

Elite Force wrote:
> Ola Bini wrote:
>> Elite Force wrote:
>>> I'd really appreciate it if you could answer my questions, thanks.
>>>
>> I would recommend that you lookup either the method Kernel#trap, the
>> class Signal, or maybe both?
>>
>> --
>> Ola Bini (http://ola-bini.bl...)
>> JvYAML, RbYAML, JRuby and Jatha contributor
>> System Developer, Karolinska Institutet (http:/...)
>> OLogix Consulting (http://www....)
>>
>> "Yields falsehood when quined" yields falsehood when quined.
>
> does ctrl-c also send a signal to the process? (i guess so)
>

Yes, C-c generates a SIGINT in most common operating systems.

--
Ola Bini (http://ola-bini.bl...)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http:/...)
OLogix Consulting (http://www....)

"Yields falsehood when quined" yields falsehood when quined.



Elite Force

7/17/2006 10:49:00 AM

0

Ola Bini wrote:
> Elite Force wrote:
>>
>> does ctrl-c also send a signal to the process? (i guess so)
>>
>
> Yes, C-c generates a SIGINT in most common operating systems.
>

Okay, thank you very much!

So my last question left open is, if there's a difference between do end
and { } blocks

--
Posted via http://www.ruby-....

Pedro Côrte-Real

7/17/2006 10:57:00 AM

0

On 7/17/06, Elite Force <eliteforce@elitemail.org> wrote:
> So my last question left open is, if there's a difference between do end
> and { } blocks

I think there's no difference in behaviour. There is a difference in
their precedence. {} blocks have higher precedence although usually
that doesn't make a difference. I just use {} when the block fits in a
single line with a single statement and do..end for everything else.

Pedro.

turlough

12/29/2007 6:18:00 PM

0

conwaycaine wrote:

> Bren?
> This is one of the Nine Brens of the Prophecy?

He would be one of the same, Conway. It is written in the Book of Unki,
and explained in the abridged version re-tailored by Greggars. I'm
having a hell of a time keeping our Irish friends calm. The faint but
distinct drum beats you hear in the distance will be getting louder soon
if the x-posting doesn't cease. See my latest exchanges with Greig. His
calls for SCI justice means the fuse is getting shorter. Maybe I should
invite George Mitchell to join the ng...

conwaycaine

12/30/2007 6:29:00 PM

0


"Turlough" <turlough@comcast.net> wrote in message
news:eIadnQqDS5dkE-vanZ2dnUVZ_ternZ2d@comcast.com...
> conwaycaine wrote:
>
>> Bren?
>> This is one of the Nine Brens of the Prophecy?
>
> He would be one of the same, Conway. It is written in the Book of Unki,
> and explained in the abridged version re-tailored by Greggars. I'm having
> a hell of a time keeping our Irish friends calm. The faint but distinct
> drum beats you hear in the distance will be getting louder soon if the
> x-posting doesn't cease. See my latest exchanges with Greig. His calls for
> SCI justice means the fuse is getting shorter. Maybe I should invite
> George Mitchell to join the ng...

Ah the Irish are ever for starting wars and rebelling against this and that.
Remember what was written about the Irish:
"All their wars are gay and all their songs are sad"
(And all their slags are awesome)