From: Nobuyoshi Nakada Date: 2011-10-05T01:46:21+09:00 Subject: [ruby-core:39941] Re: [Ruby 1.9 - Feature #5394][Open] Anonymous Symbols, Anonymous Methods Hi, (11/10/04 4:11), Kurt Stephens wrote: > Imagine that visit() needs dynamic hooks to visit different types: > >

>   def visit(obj, visitor)
>     sel = Symbol.new
>     class Array;   def *sel(visitor); each { | elem | elem.*sel(visitor) }; end; end
>     class Object;  def *sel(visitor); visitor.something(self);              end; end
>     add_visit_methods!(sel)
>     obj.*sel(visitor)
>   end
>   def add_visit_methods!(sel)
>     class Hash;    def *sel(visitor); each { | k, v | v.*sel(visitor);      end; end
>     ...
>   end
> 
> > The AnonSym send "rcvr.*sel(...)" dispatches, like a normal method send, directly to the appropriate AnonMeth for "*sel". > visit() can be extended dynamically by adding more AnonMeths bound to "*sel". > The functional "case ...; when..." version is difficult to extend and maintain and is likely to not perform as well as anon messages. > This is similar in style to Scheme letrecs, but is object-oriented. Is this double dispatching system your true goal? If so, anonymous symbol doesn't seem the only way nor the best way, for me. -- Nobu Nakada