----- Original Message -----
From: Joseph McDonald <joe / vpop.net>
To: ruby-talk ML <ruby-talk / ruby-lang.org>
Sent: Monday, October 22, 2001 2:14 PM
Subject: [ruby-talk:22987] assigning variables


>
> Hi, the following is not working as I'd like:
>
> def setvars(vars)
>   str = ""
>   vars.each do |k,v|
>     str << "#{k} = #{v}\n"
>   end
>   puts str
>   eval str
> end
>
> a = ['an' , 'array']
> b = ['another' , 'array']
> setvars( { 'a' => a, 'b' => b} )
> ========
> ./junk.rb
> a = anarray
> b = anotherarray
> ./junk.rb:9:in `setvars': (eval):1:in `setvars': undefined local variable
or method `anarray\
> ' for #<Object:0x8109c88> (NameError)
>
> What I would like is for setvars to have a variables called 'a' and
> 'b' that point to the arrays that were passed in, not a string version
> of the array.
>
> How do I make that happen?

Joe,

Sorry if I'm sidestepping the question.

I don't get *why* you want to do this... could you
just use an array of arrays?


def setvars(*args)
  p args[0]
  p args[1]
end

setvars([1,2],[2,4])

Prints:
[1, 2]
[2, 4]

I'm probably missing something...
Hal