From: Rob Biedenharn Date: 2007-12-16T09:26:19+09:00 Subject: Re: Automatic Range? On Dec 15, 2007, at 7:15 PM, Jari Williamsson wrote: > Problem is simple: > I want to know if an integer is within the range of x and y. > However, I don't automatically know which of x & y is the largest. > > Ruby accepts ranges like (5..2), although there seems to be no real > use for them. > > Anyway, is it possible to automatically create a "valid range", or > is this kind of solution the best one? > > range = x < y ? (x..y) : (y..x) > > Best regards, > > Jari Williamsson That's probably as good as it gets. However, Ranges with #end < #begin are common as arguments to String#[] such as "abcdefg"[2..-2] => "cdef". -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com