On Dec 28, 2007 10:03 AM, Paul Brannan <pbrannan / atdesk.com> wrote:
> On Fri, Dec 28, 2007 at 04:20:11PM +0900, Charles Oliver Nutter wrote:
> > I really don't know, and to be honest I haven't seen a particularly
> > compelling use case for either lexically scoped namespaces
> > or...what...temporally scoped?
> ...
> > What is the use case? I'd love to see.
>
> I would like other users to be able to import mathn without it breaking
> my code.
>
> Ideally this should work:
>
>   class Foo
>     def foo
>       # [ruby-talk:69859]
>       use namespace Mathn
>       m = Matrix[[1,2], [3,4]]
>       return m*m.inv #=> [[1,0], [0,1]]
>     end
>   end

but what about this:

def divide(a, b)
   use namespace Mathn
   a / b
 end

Now, I'd think you would want:

1 / 2 #=> 1

divide(1,2) #=> 1 / 2

The problem here it seems that you would need more than attach a
namespace to an object.  Here we want the Integer/Fixnum classes to
act differently in the context of executing the divide method, even
for objects instantiated outside and passed in.



-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/