From: Jim Weirich Date: 2005-05-28T10:08:37+09:00 Subject: Re: Coercion and ranges Philipp Kern said: > From my understanding the conversion should happen automatically when > coercion is properly implemented. Surely one could just add "to_a" to > all the ranges, but it certainly made me pondering about it. I find it a bit odd that adding two ranges results in an array, but assuming that is /really/ what you want, you could indicate a Range's willingness to be converted to an array by including a to_ary method. class Range def to_ary to_a end end > (?A..?C) + (?a..?c) + (?x..?y) => [65, 66, 67, 97, 98, 99, 120, 121] The difference between to_a and to_ary is that to_a is an explicit conversion to an array. to_ary indicates that whenever the object is found in the context where an array is desired, it can be treated as an array by calling to_ary (an implicit conversion). -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)