From: Paul Brannan Date: 2002-10-17T05:21:35+09:00 Subject: Re: Psyco On Thu, Oct 17, 2002 at 04:53:40AM +0900, Dave Thomas wrote: > I don't know about '+', but I quite often change definitions of > built-in operations. One of my current favorites is > > class NilClass > def empty? > true > end > end > > p nil.empty? > > Very useful for Web systems. 1) I don't think that modifying any class that you didn't write is EVER a good idea (it may be useful and it may even be the best solution available, but it's still not a good solution). 2) You are not changing the definition of a built-in method; you are adding a new method to a class that already exists. This is slightly different from redefining Fixnum#+. > Or, or course, we could implement C# or Java where ints are native and > have to be boxed before use. I wouldn't like to see this. That depends on what you are using the int for. In order to call 5.times, you don't have to box 5, because Fixnums are objects and respond to the same methods any other object does. However, not all methods in Object work for Fixnums. For example, I can't call Object#extend on an Integer; instead I must write a delegate class, instantiate a delegate, and call Object#extend on the delegate. Fixnums looks like objects, they smell like objects, and most of the time they even act like objects, but they are really very very special objects. Paul