From: Daniel Berger Date: 2005-11-03T00:28:50+09:00 Subject: Re: ruby-dev summary 27393-27541 Minero Aoki wrote: > Hi all, > > This is a summary of ruby-dev #27393-27541. > [ruby-dev:27417] selector namespace > > Shugo Maeda proposed a new language feature, "selector namespace". > Matz also noted this topic in his key note at Ruby Conference 2005. > > Selector namespace is a namespace of selector (method name). This > function is useful to replace methods temporarily. For example, > current jcode.rb replaces String#chop itself, which effects globally. > But with selector namespace, it effects only in "jcode" namespace. > > class String > def jcode$chop # define #chop method in jcode namespace > ... > end > end > > # "\244\242\244\244" is Japanese characters 'A'+'I' in EUC-JP > p "\244\242\244\244".chop # "\244\242\244" # wrong result > p "\244\242\244\244".jcode$chop # "\244\242" # right result > > You can omit namespace specifier ("jcode$") by using "using" syntax: > > class String > def jcode$chop() ... end > end > > using jcode > p "\244\242\244\244".chop # "\244\242" # right result > > There are still many arguments, for example: > > * whether "using" effects statically or dynamically > * '$' is ugly > * scope of "using" (file level / module level / method level) > * whether spaces are allowed around '$' For those interested, Sydney will accomplish selector namespaces via Behaviors. The exact syntax isn't settled yet, but you can look at http://www.livejournal.com/users/djberg96/50830.html for some ideas (and follow the link at the bottom to see the actual code). I definitely prefer a block level approach. I think Evan is leaning towards the "object.method using :namespace" syntax. Regards, Dan