On Apr 3, 5:42=A0am, Ryan Davis <ryand-r... / zenspider.com> wrote:
> On Apr 2, 2010, at 16:28 , Rick DeNatale wrote:
>
> > [[*(1..20)], 25, [*(30..46)]].flatten.each {|n| p n}
>
> or:
>
> class Range
> =A0 alias :to_a :to_ary
> end
>
> >> [1..20, 25, 30..46].flatten
>
> =3D> [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=3D=3D=3Dn
          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.