From: "David A. Black" Date: 2007-09-21T14:28:09+09:00 Subject: Re: Idiomatic Ruby for Array#extract / Range#length? Hi -- On Fri, 21 Sep 2007, Xavier Noria wrote: > On Sep 20, 2007, at 9:14 PM, Sebastian Hungerecker wrote: > >> Xavier Noria wrote: >>> So, in what sense succ is not required? >> >> You can have a range of objects that don't have succ. You just can't >> iterate >> over that range. > > You are saying that Ruby is implemented in a way that allows you to define an > object, use it to build a Range, and use the range in a way that does not > break the program. Agreed. > > But the documentation says "must respond to" and "as long as". That's why I > said Range assumes #<=> and #succ, because the documentation says so. > > If you use pass objects to .. that do not respond to #succ, you are indeed > feeding _invalid_ objects to .. according to the documentation. The program > may run, but that doesn't matter. The docs appear to be wrong. There's plenty of external evidence (e.g., discussions by Matz about float ranges, where he doesn't label them as invalid or advise against using them), as well as internal evidence (they work :-), suggesting that range objects do not have to respond to #succ. I think it's just out-of-date or erroneous documentation. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)