Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2019
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news.stack.nl!talisker.lacave.net!lacave.net!not-for-mail |
|---|---|
| From | "Kyle X." <haebooty@yahoo.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Re: How can I generate new variables? |
| Date | Wed, 30 Mar 2011 22:08:02 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 75 |
| Message-ID | <ddc92babca17a6f4dc20fcb6fef168b5@ruby-forum.com> (permalink) |
| References | <33ba41ea1d06d357f353d2462a951026@ruby-forum.com> <bec536840ae5b1c75ae0d824c20af7d3@ruby-forum.com> |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | talisker.lacave.net 1301540897 70303 65.111.164.187 (31 Mar 2011 03:08:17 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Thu, 31 Mar 2011 03:08:17 +0000 (UTC) |
| In-Reply-To | <bec536840ae5b1c75ae0d824c20af7d3@ruby-forum.com> |
| X-Received-From | This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway |
| X-Mail-Count | 380662 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <ddc92babca17a6f4dc20fcb6fef168b5@ruby-forum.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:2019 |
Show key headers only | View raw
First off thank you for the reply, and as you can probably tell I am very novice at ruby ><. However I am running into a few issues with this. > Using arrays. An array can contain anything--including other arrays: > > > require 'enumerator' #not necessary in ruby 1.9 > > master_arr = [] > data = [1, 2, 3, 4, 5, 6, 7, 8] > > data.each_slice(3) do |triplet| > master_arr << triplet > end > > p master_arr > > --output:-- > [[1, 2, 3], [4, 5, 6], [7, 8]] I am writing this for SketchUP so I am using Ruby 1.8.6 and am having an issue with require 'enumerator', as it does not exist in their library as far as I can tell --- in turn the "each_slice" command does not function. I was wondering if you could help me understand this command better as well. "data.each_slice(3) do |triplet|" The "(3)" here means slice after 3 entries in data correct? The word triplet used, is this word required or could it be any word as long as it is consistent below i.e. : do |x| master_arr << x? Sorry for the basic question, but I just want to clarify. > > The names of the arrays are: > > master_arr[0] > master_arr[1] > master_arr[2] > > Voila! But in ruby, you rarely need to refer to index positions in an > array because you can do this: > > master_arr.each do |arr| > p arr > end > > --output:-- > [1, 2, 3] > [4, 5, 6] > [7, 8] > > Or this: > > master_arr.each do |arr| > new_arr = arr.map do |element| > element * 2 > end > > p new_arr > end > > --output:-- > [2, 4, 6] > [8, 10, 12] > [14, 16] The rest I think I have figured out, but still not 100% on the map function. Thank you again for your time. -- Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How can I generate new variables? "Kyle X." <haebooty@yahoo.com> - 2011-03-30 19:42 -0500
Re: How can I generate new variables? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-30 20:14 -0500
Re: How can I generate new variables? "Kyle X." <haebooty@yahoo.com> - 2011-03-30 22:08 -0500
Re: How can I generate new variables? Gunther Diemant <g.diemant@gmx.net> - 2011-03-31 03:08 -0500
Re: How can I generate new variables? "Kyle X." <haebooty@yahoo.com> - 2011-03-31 14:30 -0500
Re: How can I generate new variables? Robert Klemme <shortcutter@googlemail.com> - 2011-03-31 03:11 -0500
Re: How can I generate new variables? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-31 20:06 -0500
Re: How can I generate new variables? "Kyle X." <haebooty@yahoo.com> - 2011-04-02 01:18 -0500
Re: How can I generate new variables? Robert Klemme <shortcutter@googlemail.com> - 2011-04-04 02:15 -0500
csiph-web