Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Defining bunch of vars dynamically
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eilie  
View profile  
 More options Feb 7, 5:59 pm
Newsgroups: comp.lang.ruby
From: Eilie <Ei...@what-are-you-looking.for>
Date: Tue, 7 Feb 2012 22:59:57 +0000 (UTC)
Local: Tues, Feb 7 2012 5:59 pm
Subject: Defining bunch of vars dynamically
Hello, everyone.

Subj on 1.9.3.
I tryed already:

5.times {|n| eval "house#{n} = Array.new(5)"}

Thats works but only in block scope, how can i define 5 vars in global
scope(with ability to access it out of block)?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sreservoir  
View profile  
 More options Feb 7, 6:08 pm
Newsgroups: comp.lang.ruby
From: sreservoir <sreserv...@gmail.com>
Date: Tue, 07 Feb 2012 18:08:08 -0500
Local: Tues, Feb 7 2012 6:08 pm
Subject: Re: Defining bunch of vars dynamically
On 02/07/2012 05:59 PM, Eilie wrote:

> Hello, everyone.

> Subj on 1.9.3.
> I tryed already:

> 5.times {|n| eval "house#{n} = Array.new(5)"}

> Thats works but only in block scope, how can i define 5 vars in global
> scope(with ability to access it out of block)?

you ... probably don't want to. having to dynamically generate your
variable names is generally a sign that either you're using foreign data
for them, or they're closely related. or both.

in the former case, doing that would be unsafe, and you should probably
use some sort of array (or a hash). the latter case ... you should also
probably do that.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eilie  
View profile  
 More options Feb 7, 9:41 pm
Newsgroups: comp.lang.ruby
From: Eilie <Ei...@what-are-you-looking.for>
Date: Wed, 8 Feb 2012 02:41:45 +0000 (UTC)
Local: Tues, Feb 7 2012 9:41 pm
Subject: Re: Defining bunch of vars dynamically
On 2012-02-07, sreservoir <sreserv...@gmail.com> wrote:

Yeah, you're right. Hash better choice for that, sorry for disturbance.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Klemme  
View profile  
 More options Feb 8, 9:44 am
Newsgroups: comp.lang.ruby
From: Robert Klemme <shortcut...@googlemail.com>
Date: Wed, 8 Feb 2012 06:44:06 -0800 (PST)
Local: Wed, Feb 8 2012 9:44 am
Subject: Re: Defining bunch of vars dynamically

On Wednesday, February 8, 2012 3:41:45 AM UTC+1, Eilie wrote:
> On 2012-02-07, sreservoir <sreserv...@gmail.com> wrote:
> > On 02/07/2012 05:59 PM, Eilie wrote:
> >> I tryed already:

> >> 5.times {|n| eval "house#{n} = Array.new(5)"}
> Yeah, you're right. Hash better choice for that, sorry for disturbance.

Why not an Array?  You are indexing by integer anyway.

Assuming you really want five Arrays of length five each:

houses = Array.new(5) { Array.new(5) }

Cheers

robert


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »