# Question about testing/removing signals after signal\_connect()

**URL:** <https://www.ruby-forum.com/t/question-about-testing-removing-signals-after-signal-connect/244783>\
**Category:** Ruby-Gnome 2\
**Created:** [June 13, 2016, 11:55pm UTC](https://www.ruby-forum.com/t/question-about-testing-removing-signals-after-signal-connect/244783 "2016-06-13T23:55:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [June 13, 2016, 11:55pm UTC](https://www.ruby-forum.com/t/question-about-testing-removing-signals-after-signal-connect/244783/1 "2016-06-13T23:55:02Z")

</div>

Hi:

I’m having a problem with connecting signals. I need to call  
signal\_connect several times with the same method. However, I don’t  
want it to execute the method several times:

def do\_something()  
puts “Hello”  
end

def connect  
if button.signals\_array.includes?(“clicked”,do\_something)  
button.signal\_connect(“clicked”) {do\_something }  
end  
end

10.times do  
connect  
end

I want it to output:

Hello

only once.

This would work great except that there’s no button.signals\_array  
available in Gtk as far as I can tell.

How can I test a widget to see if a signal is already attached to it? I  
know there’s a list of signals that get executed, and connect\_signals  
adds to that list. How can I check that list for duplicates?

Thanks!

Eric
