From: Michael Neumann Date: 2005-01-06T11:54:38+09:00 Subject: Re: Seeking info on keyword parameters itsme213 wrote: > "Yukihiro Matsumoto" wrote in message > > >>|If a subclass of Symbol like SelectorSymbol also had a @namespace slot to >>|provide selector namespaces (which would be great with Ruby's modules and >>|re-opening of classes; SmallScript does something similar), we would also >>|need some way to associate a namespace with a selector symbol. e.g. >>| x.send :move # which namespace? symbol or selector symbol? >>| x.send N1::move # ah, N1's :move selector symbol >>| x.send :move # send could treat :move symbol as default_ns::move >>|selector symbol? >> >>I'm not sure I get you, but I feel like you're suggesting something >>interesting. Let me consider. Detailed explanation would be welcomed. > > > When defining a method (via def... or define_method) we need to indicate > which namespace the selector belongs to; and when invoking a method via > x.send or x.foo, we need to indicate which namespace selector we are using. > > -------------- > First for invocations of the form: x.send(selector, *args) > #send needs to know the namespace of the selector so it can lookup the > correct method. A subclass of Symbol, say SelectorSymbol, could have a > @namespace slot. NameSpace#lookup(symbol) could return a SelectorSymbol, and > all methods (or unbound methods) could be indexed by SelectorSymbols. > > So I can now write in verbose form: > x.send my_namespace.lookup(:move) other_args > > We need a better syntax to indicate which namespace. Something like: > x.send myns::move other_args # :: resolves to a SelectorSymbol > or > x.send myns:.move other_args # :. resolves to a SelectorSymbol Why not use blocks that change what the current namespace is? namespace(:myns) { x.send :move otherargs ... } That should be thread-local of course. Everything inside the block is executed in the :myns namespace. Regards, Michael