From: Matt Mencel Date: 2010-04-02T05:49:41+09:00 Subject: Re: Dynamic Method Calls Hmmm...can't seem to make that happen.... class LdapAccount < ActiveRecord::Base serialize :objectclass, Array end I think because I'm wrapping the value in quotes turning the Array v to a String when it's saved in the model... c.send("#{k.downcase}=", "#{v}") Produces... objectclass was supposed to be a Array, but was a String I can't take the quotes off though because it doesn't save correctly in the database. Using this code, entries end up looking like this when I don't wrap v in quotes. c.send("#{k.downcase}=", v) '--- - inetLocalMailRecipient - person - posixAccount - sambaSamAccount - shadowaccount - top ' Matt ----- Original Message ----- From: "AMILIN Aurélien" To: "ruby-talk ML" Sent: Thursday, April 1, 2010 3:14:00 PM Subject: Re: Dynamic Method Calls You should try to serialize your array instead of saving it as a string if you are using ActiveRecord try this : class LdapAccount < ActiveRecord::Base serialize :mails, Array end then when you get the accout from the database : my_account.mails return an Array Le 01/04/2010 21:59, Matt Mencel a écrit : > This did it...thanks for the assistance... :) > > c.send("#{k.downcase}=", "#{v}") > > > Every record.attributes value is an Array, even if they are single-valued. When I store the data into the LdapAccount model...it just stores the data as a String. Which is fine for single-valued arrays, but the multi-valued is a problem. I could do the following... > > c.send("#{k.downcase}=", "#{v.inspect}") > > Which would store every single or multi valued array in the model as a String like so... > single: ["SOMEVAL"] > multi: ["val1","val2","val3",etc...] > > But that may be more work when I want to pull that data back out at some point in the future. Should I store the single valued attributes as a plain String and the multi-valued attributes as an Array String like above? > > Something like this maybe... > > LdapAccount.create(:uid => record.attributes["uid"].to_s) do |c| > record.attributes.each_pair do |k,v| > # v is an array of single or multi attribute values > if v.size > 1 > c.send("#{k.downcase}=", "#{v.inspect}") > else > c.send("#{k.downcase}=", "#{v}") > end > end > end > > Any thoughts? > > Thanks, > Matt > > > > ----- Original Message ----- > From: "Ryan Davis" > To: "ruby-talk ML" > Sent: Thursday, April 1, 2010 1:42:56 PM > Subject: Re: Dynamic Method Calls > > > On Apr 1, 2010, at 11:35 , Andrea Dallera wrote: > > >> Whoopsie, i'm really sorry. It should be something like: >> >> c.send("#{k}=".to_sym, v) >> > .to_sym is unnecessary > > > >