# Checking types of objects in signal handlers

**URL:** <https://www.ruby-forum.com/t/checking-types-of-objects-in-signal-handlers/116197>\
**Category:** Ruby-Gnome 2\
**Created:** [October 3, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/checking-types-of-objects-in-signal-handlers/116197 "2007-10-03T12:03:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [October 3, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/checking-types-of-objects-in-signal-handlers/116197/1 "2007-10-03T12:03:00Z")

</div>

in the example on  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMenu](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMenu)  
it says:

window.signal\_connect(“button\_press\_event”) do |widget, event|  
if event.kind\_of? Gdk::EventButton  
if (event.button == 3)  
menu.popup(nil, nil, event.button, event.time)  
end  
end  
end

isn’t the event.kind\_of? test redundant, or is this test something  
all signal handlers should be doing?

martin

---

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [October 4, 2007, 7:50am UTC](https://www.ruby-forum.com/t/checking-types-of-objects-in-signal-handlers/116197/2 "2007-10-04T07:50:40Z")

</div>

Seems redundant to me since the signal is only emitted  
if the button was pressed. But maybe the additional  
check is important to ensure that something is a  
Gdk::EventButton (but i cant think of a reason, maybe  
someone could add a # comment that explains this briefly)

Also I think using :button\_press\_event would be nicer and  
the

if (event.button == 3)

() parens arent needed afaik

Martin P. wrote:

> in the example on  
> [http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMenu](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMenu)  
> it says:
> 
> window.signal\_connect(“button\_press\_event”) do |widget, event|  
> if event.kind\_of? Gdk::EventButton  
> if (event.button == 3)  
> menu.popup(nil, nil, event.button, event.time)  
> end  
> end  
> end
> 
> isn’t the event.kind\_of? test redundant, or is this test something  
> all signal handlers should be doing?
> 
> martin

---

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [October 4, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/checking-types-of-objects-in-signal-handlers/116197/3 "2007-10-04T18:44:33Z")

</div>

Hi,

On Wed, 03 Oct 2007 10:39:16 +0100  
Martin P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> isn’t the event.kind\_of? test redundant, or is this test something  
> all signal handlers should be doing?

Sure. You don’t need this here.  
I removed this from the tutorial.

BTW, if you use “event” instead of “button\_press\_event”,  
you’ll need to check kind\_of?.

window.signal\_connect(“event”) do |widget, event|  
if event.kind\_of? Gdk::EventButton  
if (event.button == 3)  
menu.popup(nil, nil, event.button, event.time)  
end  
end  
end

–  
.:% Masao M.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
