From: Roger Pack on
Anybody know if there's an easy way to accomplish the equivalent of
this:

[1..20, 30..46].each{|n|
# n = 1,2,3,4,5..30, 31, 32
}

?

Thanks!
-rp
--
Posted via http://www.ruby-forum.com/.

From: David Springer on
Will this work:
[1..20,30..46].each{|r| r.each {|n| p n}}

David
--
Posted via http://www.ruby-forum.com/.

From: Jonathan Nielsen on
> [1..20, 30..46].each{|n|
>  # n = 1,2,3,4,5..30, 31, 32
> }

Only thing that comes to mind for me is

r1 = 1..20
r2 = 30..46
(r1.to_a + r2.to_a).each{|n| puts n}

Probably not the best solution, but works...

-Jonathan Nielsen

From: David Springer on
Adding parentheses may make it a little clearer:
[(1..20),(30..46)].each{|r| r.each {|n| p n}}
David

--
Posted via http://www.ruby-forum.com/.

From: Roger Pack on
David Springer wrote:
> Will this work:
> [1..20,30..46].each{|r| r.each {|n| p n}}

Yeah that works.

I guess if I need individual values in there (like 25) I can do

[1..20, 25..25, 30..46].each{|r| r.each {|n| p n}}

So that'll work.
Thanks.
-rp
--
Posted via http://www.ruby-forum.com/.

 |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: A little help needed
Next: ANN: Sequel 3.10.0 Released