From: Robert Klemme Date: 2008-11-18T00:55:44+09:00 Subject: Re: mult dimensional arrays in ruby 2008/11/17 Sijo Kg : > Hi > What I am trying to do below is I have to enter two rows to the table > contact_address_types like > > description(string) default_item(boolean) enabled(boolean) > Home f t > Business f t > > Then I tried like > > CONTACT_ADDRESS_TYPES = [["Home","f","t"],["Business","f","t"]] > def self.up What is self here? > CONTACT_ADDRESS_TYPES.each do |array| > ContactAddressType.create(:description => array[0]) > ContactAddressType.create(:default_item => array[1]) > ContactAddressType.create(:enabled => array[2]) > end You need to use #map! instead of #each if you want to change CONTACT_ADDRESS_TYPES in place. However, I'd think this is bad design because you are changing the types of objects in a constant Array. I'd rather do it differently (see below): > end > > > But this not working Is this the correct way to do this?Please How about irb(main):001:0> ContactAddressType = Struct.new :decription, :default_item, :enabled => ContactAddressType irb(main):002:0> CONTACT_ADDRESS_TYPES = [ irb(main):003:1* ContactAddressType.new("Home", false, true), irb(main):004:1* ContactAddressType.new("Business", false, true), irb(main):005:1* ] => [#, #] irb(main):006:0> ? Cheers robert -- remember.guy do |as, often| as.you_can - without end