Wow!  Thanks Dave!

I assume then that its not possible with Ruby out of the box?  I have been
amazed at how flexible Ruby is.

Do people think that this is such an esoteric feature that it would not be
worth adding to the language?

John.

"Dave Thomas" <Dave / PragmaticProgrammer.com> wrote in message
news:m2ptxsvjv1.fsf / zip.local.thomases.com...
> "John" <nojgoalbyspam / hotmail.com> writes:
>
> > I wonder if anyone has any suggestions on how to create a method that
> > matches its name based on a regular expression.  For instance:
>
> How about something like this:
>
>      class Dave
>
>        # This part implements the 'alias_regexp' thingie
>
>        @@_method_matches = {}
>
>        def self.alias_regexp(regexp, name)
>          @@_method_matches[regexp] = name
>        end
>
>        def method_missing(name, *args)
>          name = name.to_s
>          @@_method_matches.each do |regexp, target|
>            if regexp =~ name.to_s
>              return send(target, *args)
>            end
>          end
>          super
>        end
>
>
>        # and this demonstrates it in action
>
>        def do_it
>          puts "do it"
>        end
>
>        def dont
>          puts "dont"
>        end
>
>        alias_regexp /no.*/, :dont
>        alias_regexp /nyet.*/, :dont
>        alias_regexp /yes.*/, :do_it
>      end
>
>      d = Dave.new
>      d.no_way
>      d.nyet_way
>      d.yes_please
>
>
> Cheers
>
>
> Dave
>
>