From: Pit Capitain Date: 2005-04-30T04:18:09+09:00 Subject: Re: method_missing question Joe Van Dyk schrieb: > >Currently, I have a class that has a bunch of methods (that a GUI does >a callback on) that are like > > def menu_zoom_100_activate > @display.zoom(100) > end > > def menu_zoom_250_activate > @display.zoom(250) > end > > def menu_zoom_500_activate > @display.zoom(500) > end > >Could I use #method_missing to make this better? You should be able to use method_missing, but you could also do something like class Handler [ 100, 250, 500 ].each do |factor| define_method("menu_zoom_#{factor}_activate") do @display.zoom(factor) end end end or for some more syntax sugar define a class method class Handler class << self def zoom_methods(*factors) ...see above... end end zoom_methods 100, 250, 500 end Regards, Pit