Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6449

Re: Defining bunch of vars dynamically

From sreservoir <sreservoir@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Defining bunch of vars dynamically
Date 2012-02-07 18:08 -0500
Organization A noiseless patient Spider
Message-ID <jgsato$9vh$1@dont-email.me> (permalink)
References <slrnjj3b7d.4ui.Eilie@localhost.localdomain>

Show all headers | View raw


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.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Defining bunch of vars dynamically Eilie <Eilie@what-are-you-looking.for> - 2012-02-07 22:59 +0000
  Re: Defining bunch of vars dynamically sreservoir <sreservoir@gmail.com> - 2012-02-07 18:08 -0500
    Re: Defining bunch of vars dynamically Eilie <Eilie@what-are-you-looking.for> - 2012-02-08 02:41 +0000
      Re: Defining bunch of vars dynamically Robert Klemme <shortcutter@googlemail.com> - 2012-02-08 06:44 -0800

csiph-web