I wonder if this is possible as i find myself repeating code which is
not a good sign, Kent Becks “3 strikes and your out” rule.
I am reading in a bunch of xml objects using REXML. So for instance a
couple are below but there could be a lot more.
Each element above corresponds to a model in the database so i need a
generic method which will loop through all the elements in the XML file
and add them to the corresponding model table in the database if they
dont already exist and then return the object so it can be updated to
the parent model.
for element in element.elements
#i need to get the model in the tempmodel object from the xml elements
#element.name will return Client for the 1st xml element
tempmodel = element.name
#the below would return a Client object Client.find_by_name(Building
object = tempmodel.find_by_name(element.text)
object = tempmodel.new(:name => element.text)
#the below would turn Client into client as thats the method
tempmethod = tempmodel.downcase
project.tempmethod = object
Is the above possible and if so can anyone offer some advice or
examples, im searching the API but cant find what i am looking for.