From: Eric Hodel Date: 2006-08-10T02:18:18+09:00 Subject: Re: How to react on nil or wrong object-type as parameter On Aug 9, 2006, at 1:25 AM, Robert Klemme wrote: > I sort of agree to both of you and I think despite this thread you > maybe not too far away from each other. > > On 09.08.2006 00:19, Eric Hodel wrote: >> This is why you shouldn't call or define #to_xxx methods, how and >> where they are supposed to be used is confusing, convoluted and >> error-prone. They aren't supposed to be used where you think they >> are supposed to be used. > > I agree that implementing and invoking #to_int and #to_str needs > considerably more consideration than their counterparts #to_i and > #to_s - and you'll rarely see them implemented. > > The standard lib has several classes which define these methods: > you can try it out: > > ruby -e '%w{to_int to_str}.each {|mn| print "\nMethod ", mn, ":\n"; > ObjectSpace.each_object(Module) {|cl| p cl if cl.instance > _methods.any? {|m| mn == m}}}' In 1.9, Exception no longer implements #to_str, leaving only String and NameError::message. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com