From: Li Chen Date: 2009-01-09T06:02:22+09:00 Subject: code factoring problem Hi all, I use FxRuby to do some GUI programing. I define a method to handle the same stuff if a button is either selected(SEL_COMMAND) or 'enter' key is pressed (SEL_KEYPRESS). Since the codes for each event are the same,I try to factor them out. But I am not sure about the syntax. I wonder if someone can give me a hand. Thanks, Li ###original codes### def a_method @button_next.connect(SEL_COMMAND) do # many lines for handling event A ... ... # end @button_next.connect(SEL_KEYPRESS) do # many lines for handling event A ... ... # end end ###### code formats after factoring def a_method if @button_next.connect(SEL_COMMAND)==true or @button_next.connect(SEL_KEYPRESS)==true do # many lines for handling event A ... ... # end end -- Posted via http://www.ruby-forum.com/.