From: Joe Van Dyk Date: 2005-04-30T09:45:30+09:00 Subject: Re: method_missing question On 4/29/05, Pit Capitain wrote: > 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 > DING DING DING. The above worked perfectly. Thanks!