Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Array Building idiom

Reply
Thread Tools

Array Building idiom

 
 
John-Mason P. Shackelford
Guest
Posts: n/a
 
      08-10-2006
What other idioms do you use for:

a=[]; 10.times{a<<callme() }
Array.new(10).map{ callme() }

Note: callme() returns a new value with each call.

Do I understand correctly that the former will be illegal under 1.9.1?
--
John-Mason Shackelford

Software Developer
Pearson Educational Measurement

2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
john-
http://pearsonedmeasurement.com

 
Reply With Quote
 
 
 
 
Martin DeMello
Guest
Posts: n/a
 
      08-10-2006
On 8/11/06, John-Mason P. Shackelford <> wrote:
> What other idioms do you use for:
>
> a=[]; 10.times{a<<callme() }
> Array.new(10).map{ callme() }
>
> Note: callme() returns a new value with each call.
>
> Do I understand correctly that the former will be illegal under 1.9.1?


Illegal on what basis? Also, Array.new takes a block while
constructing the array, so you needn't use map:

irb> Array.new(10, rand(100))
=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

irb> Array.new(10) { rand(100) }
=> [74, 59, 97, 59, 65, 12, 64, 16, 2, 59]

martin

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefighters at the site of WTC7 "Move away the building is going to blow up, get back the building is going to blow up." Midex Python 24 05-07-2007 04:23 AM
Wireless building-to-building 101 Tim Jacob Wireless Networking 2 02-17-2006 09:46 AM
Simplified DOM idiom for building XML - revisited Steve Jorgensen XML 4 08-28-2005 08:54 PM
Idiom for array index that I'm foreach'ing over? Tim Shoppa Perl Misc 45 12-23-2003 04:30 PM
Building to Building wireless Patriot Cisco 2 11-04-2003 05:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57