From: mengx@... Date: 2002-01-02T23:22:33+09:00 Subject: [ruby-talk:30041] Re: A Bug or something else? > > Well, in ruby a private method is a method that can be called only in a > function form (i.e. it can have only self as a receiver). Here you are in > a special where ruby want to convert a value to a string, and in this case > it can call any methods (public, private, ...) > Thanks. I guess this is a special case when nil is used in something like string substitution. Below are some examples: class NilClass private :to_s end nil.to_s => undefined method. Yet "#{nil}" => "" I'd consider it against POLS. Apparently, the C program does not use "to_s" method. Secondly, as I said before, it would be nice that "nil" does not respond to "to_s, to_i, to_a" at all. > m> about the reasoning for the existence of methods for "nil", such as "to_a", > m> "to_i", "to_s". Can an exception be raised for this scenario and the one > m> below? > > m> a = nil > > m> a == 1 => false (even after the undef) > > Well here you have written something like > > a.== 1 > > this mean that if you undef #== for NilClass it will work > > pigeon% ruby > class NilClass > undef == > end > a = nil > a == 1 > ^D > -:5: undefined method `==' for nil (NameError) > pigeon% > > it's still work with > > 1 == a > That is exactly what I meant. It is impossible to achieve what a static typed language can do for this purpose, but for "nil", it would not be too hard to conduct a check for "nil", a special and straitforward case in either C interpreter or Ruby itself. Does it sound reasonable? I am a little obsessed with this since it is a great danger to silently corrupt data due to common program errors. Thanks -Ted