From: Roger Pack Date: 2010-09-09T01:00:45+09:00 Subject: [ruby-core:32152] Re: Ruby 2.0 Wiki/Wish-list? > |namespace my_own > | �class String > | � � def my_own_method > | � �end > | �end > |end > | > |then I wouldn't be polluting the (global) String class. > > How would this namespace thing works? In general, the goal would be "scoped monkey patching" since I sometimes want to monkey patch, say, Float, but only within my own lib. My first thought at how to implement it would be namespace A do class Float def my_method "%f" % self end end end and then later namespace A do 3.3.my_method # this would work by, on method_missing, search for method in A::Float end So I suppose this is about the same as the proposal discussed in 2009 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/22330 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/22295 Now how it to actually *accomplish* this I have no idea, if it's block syntax. If it's per-file selector, then you could use method_missing to lookup any namespaces and see if it should be called there. Both feel a bit kludgey, so I'm not sure. -r