On 03.01.2007 07:46, Krekna Mektek wrote:
> I'd like to know how I can unroll an array into some instance variables.
> 
> like this:
> 
> pseudocode:
> 
> class Person
>  def initialize
>    @name,@address,@place_of_birth,@whatever = Array
>  end
> end
> 
> --* So I can call  *--
> 
> person1 = Person.new(personal_data)
> 
> personal_data = ['Eric','Meanstreet 3','Buenos Aires','etc']
> 
> I hope it's clear what I'd like to know..

Not exactly.  I'm irritated by the order of statements.  You use 
"personal_data" before you assigned to it.

If you just accidentally got the order wrong: you can do it as Farrel 
pointed out.  However, I would generally recommend having explicit 
parameters.  So, while you can do

def initialize(parms)
   @name,@address,@place_of_birth,@whatever = parms
end

I would prefer

def initialize(name,address,place_of_birth,whatever)
   @name = name
   @address = address
   @place_of_birth = place_of_birth
   @whatever = whatever
end

It's safer and gives you automatic checking of argument lists - at least 
Ruby checks the number of arguments for you.  If you use the array 
approach some or even all values may end up nil without you noticing it.

Kind regards

	robert