ruby on rails - Modify a list of variables when passed as a string -


i have ruby instance of class (x) , list of variables string ["var1", "var2", .. , "varn" ]. have function modify these values net effect this:

def modify(instance_obj, arrray_of_variables)   # end 

net effect should be:

x.var1 = modifyvar(x.var1) x.var2 = modifyvar(x.var2) .. x.varn = modifyvar(x.varn) 

all variables assumed strings.

edit (more information): actual problem i'm trying solve 10 of model classes, have few string variables store in db json strings. have 2 functions parse_from_json (which should called after_find) , serialize_to_json (called before_save). since done quite few model classes (around 10 model classes , total of 30 variables or so), want move separate function instead of defining these functions each model class.

you try this.

def modify(instance_obj, arrray_of_variables)   arrray_of_variables.each |variable|     instance_obj.send("#{variable}=", modifyvar(instance_obj.send(variable)))   end end 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -