From: Mathieu Bouchard Date: 2001-06-04T07:04:57+09:00 Subject: [ruby-talk:16190] Re: RCR: treatment of ranges within array definitions On Mon, 4 Jun 2001, Phil Tomson wrote: > In perl if I put a range into an array that range is expanded so that the > array contains each element described by the range (Perl doesn't have a > range type). So in perl if I do: There is no "range" in Perl so it is not "expanded" into an "array". Using the dot-dot operator in list context creates a list of consecutive elements. List juxtaposition means list concatenation. A list may be assigned to an array. > So, here is my poposal: When a range appears within an array definition > (between '[' and ']') expand the range into an array containing each of > the elements defined by the range unless the range is defined within > parenthesis. > [...] They would have to change it to: [(0..4),(3..5),(20..24)] > in order for it to work that way if this RCR were implemented. Instead of adding such special cases to the language, I'd recommend using something like this: def expand_ranges(a) r=[] a.each{|e| case e when Range; r.push *(e.to_a) else r.push e; end } r } matju