From: Chris Carter Date: 2007-06-22T12:42:05+09:00 Subject: Re: Dynamic method creation On 6/21/07, Matt wrote: > Hi! Is there a way to create a regular expression type method and pull > the pieces from that? I can find how to add methods dynamically but > what I really need is something like this. > > def _requires id > self.requires name, id > end > > > def requires name, id > ... > end > > so i could type something like test_requires 4 and it would transmit the > parameters test and 4 to the requires method. > > thanks! > > Matt > > -- > Posted via http://www.ruby-forum.com/. > > The following (untested) code should work. def method_missing sym,*args,&block sym = sym.to_s if sym =~ /(\w+)_requires/ && args.size == 1 requires $1, *args end end -- Chris Carter concentrationstudios.com brynmawrcs.com