From: Rick DeNatale Date: 2007-12-29T05:21:39+09:00 Subject: Re: Matz says namespaces are too hard to implement - why? On Dec 28, 2007 1:28 PM, Paul Brannan wrote: > On Sat, Dec 29, 2007 at 12:54:28AM +0900, Rick DeNatale wrote: > > > > 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 > ... > > What causes the integer 1 to use the '/' method monkeypatched in Mathn > > in one case and not the other? > > In the first case (1 / 2), the Mathn namespace is not active, so the > usual integer division method applies. > > In the second case (divide), the Mathn namespace is active, so Integer#/ > defined in the Mathn namespace applies. Okay, I read your pastie again, and I understand the unnatural acts being performed a bit more. All I can say is that it makes me want to run away in horror. There are also some other little issues, for example, the way mathn changes Fixnum and Bignum class Fixnum alias / quo end class Bignum alias / quo end and in Ruby 1.9 these become: class Fixnum remove_method :/ alias / quo end class Bignum remove_method :/ alias / quo end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/