From: Mark Hubbart Date: 2004-04-22T03:21:09+09:00 Subject: Re: A Ruby WishList On Apr 21, 2004, at 5:42 AM, Mauricio Fern�ndez wrote: >> Auto Initialization of variables >> When I write code like this > >> sum = 0 >> 10.times{|n| sum = sum + n } > > having sum be auto-initialized to 0 is *evil*. Should it be 0, '', > [], {}? How would Ruby know? Just a thought... What if there was a class: class Nothing def +(other) other + self end def -(other) other - self end #..... def to_int 0 end def to_str "" end #.... end basically, this would be a class that would take on the empty version of whatever was necessary. This would probably only work with the basic classes, though... since +, -, etc can be redefined, you can't assume that obj.+() requires an argument of it's own kind; or that a+b == b+a, etc. So I guess this wouldn't really wwork, after all. :) cheers, --Mark