From: Rick DeNatale on
On Fri, Apr 2, 2010 at 6:33 PM, Roger Pack <rogerpack2005(a)gmail.com> wrote:
> 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.

or

[[*(1..20)], 25, [*(30..46)]].flatten.each {|n| p n}

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

From: Tomo Kazahaya on
[Note: parts of this message were removed to make it a legal post.]

You can splat objects with to_a everywhere.
[*1..20, 25, *30..46].each {|n| p n}

Tomo
On Fri, Apr 2, 2010 at 7:28 PM, Rick DeNatale <rick.denatale(a)gmail.com>wrote:

> On Fri, Apr 2, 2010 at 6:33 PM, Roger Pack <rogerpack2005(a)gmail.com>
> wrote:
> > 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.
>
> or
>
> [[*(1..20)], 25, [*(30..46)]].flatten.each {|n| p n}
>
> --
> Rick DeNatale
>
> Blog: http://talklikeaduck.denhaven2.com/
> Github: http://github.com/rubyredrick
> Twitter: @RickDeNatale
> WWR: http://www.workingwithrails.com/person/9021-rick-denatale
> LinkedIn: http://www.linkedin.com/in/rickdenatale
>
>

From: Caleb Clausen on
On 4/2/10, Roger Pack <rogerpack2005(a)gmail.com> wrote:
> 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
> }
>
> ?

Oh, I wish for a real integer set class!

From: Rick DeNatale on
On Fri, Apr 2, 2010 at 8:20 PM, Tomo Kazahaya <tomonacci(a)gmail.com> wrote:
> [*1..20, 25, *30..46]

I'm afraid that that give a syntax error in both 1.8.7 and 1.9


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

From: Gary Wright on

On Apr 2, 2010, at 10:01 PM, Rick DeNatale wrote:

> On Fri, Apr 2, 2010 at 8:20 PM, Tomo Kazahaya <tomonacci(a)gmail.com> wrote:
>> [*1..20, 25, *30..46]
>
> I'm afraid that that give a syntax error in both 1.8.7 and 1.9

I only have 1.9.0 handy, but did something change when I wasn't looking:

$ ruby1.9 -v
ruby 1.9.0 (2008-07-25 revision 18217) [i686-darwin9]
$ ruby1.9 -e 'p [*1..20, 25, *30..46]'
[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]

Gary Wright


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