Prev: A little help needed
Next: ANN: Sequel 3.10.0 Released
From: Roger Pack on 2 Apr 2010 17:08 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 2 Apr 2010 17:14 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 2 Apr 2010 17:14 > [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 2 Apr 2010 17:42 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 2 Apr 2010 18:33
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/. |