From: Intransition Date: 2010-04-03T21:22:53+09:00 Subject: Re: combined ranges... On Apr 3, 5:42 am, Ryan Davis wrote: > On Apr 2, 2010, at 16:28 , Rick DeNatale wrote: > > > [[*(1..20)], 25, [*(30..46)]].flatten.each {|n| p n} > > or: > > class Range >   alias :to_a :to_ary > end > > >> [1..20, 25, 30..46].flatten > > => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46] > > I think that's a lot prettier... seems safe to me :D I can't think of any reason that it wouldn't be safe --and if it is then it's a very nice solution. But Ryan did you use the :D emoticon to suggest that it really was unsafe? In any case, to avoid the large footprint of using flatten you could try something like module Enumerable def visit each do |n| if Enumerable===n n.each{ |*s| yield(*s) } else yield(n) end end end end [1..20, 25, 30..46].visit{ |n| p n } *I did not test this code, so it may need tweaking. But you get the idea.