From: Logan Capaldo Date: 2006-04-21T03:53:13+09:00 Subject: Re: [SUMMARY] Refactoring (#75) On Apr 20, 2006, at 12:33 PM, Matthew Moss wrote: > Rather than mucking around with method_missing, let's just extend the > language so method names are regular expressions: > > class MusicList > def /sort_by_(.+)/ (*margs) # "margs" == matches as args > @list.sort_by { |song| song.send(margs[0]) > end > end > > > Method name resolution might be hell, though.... I would rather have something like class MusicList sortable_attr_accessor :song, :duration # does everything # attr_accessor used to do, but # also defines #sort_by_song, # etc. end or class MusicList can_sort_by :song, :duration end I guess what I'm saying is I'd rather have explicitly defined generated methods than one method that alters it's behavior based on its name. Of course these methods would not prevent you from sorting by anythiong else or even still having the method_missing in there, I just think it looks cleaner, in this case.