On Wed, 2007-01-03 at 15:50 +0900, Farrel Lifson wrote:
> On 03/01/07, Krekna Mektek <krekna@gmail.com> wrote:
> > Hi,
> >
> > 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..
> >
> > Krekna
> >
> >
>
> You do it exactly as you described
>
> irb(main):001:0> personal_data = ['Eric','Meanstreet 3','Buenos Aires']
> => ["Eric", "Meanstreet 3", "Buenos Aires"]
> irb(main):002:0> name,address,place_of_birth = personal_data
> => ["Eric", "Meanstreet 3", "Buenos Aires"]
> irb(main):003:0> name
> => "Eric"
> irb(main):004:0> address
> => "Meanstreet 3"
> irb(main):005:0> place_of_birth
> => "Buenos Aires"
> irb(main):006:0>
>
What if you had an array of arrays of persons? Something like:
[ ["name_1", "add_1", "birth_1"], ["name_2", "add_2", "birth_2"] ]
so that each person could be processed in a loop?