From: Li Chen Date: 2009-01-09T09:41:22+09:00 Subject: Re: code factoring problem Matthew Moss wrote: >Just do this: > > if @button_next.connect(SEL_COMMAND) or > @button_next.connect(SEL_KEYPRESS) do > Alternatively, if this list could grow larger, you might consider > something like this: > > def a_method > sels = [SEL_COMMAND, SEL_KEYPRESS] > if sels.any? { |sel| @button_next.connect(sel) } do > # many lines for handling event A > ... > ... > # > end > end > > Just extend `sels` to include the appropriate events/signals. Hi Matt, Thanks. But none of them works for me. I also try codes from Joel(another reply) and it works perfectly: [SEL_COMMAND, SEL_KEYPRESS].each do |sel| @button_next.connect(sel) {...} end I could not figure out why your codes don't work for me. Li -- Posted via http://www.ruby-forum.com/.