Instantiating a class using Kernel.const_get

hello all,
i have a model which needs to instantiate a class depending on the
string name which is passed to initialize()

so, to get my Person class instance, i do:
person = Kernel.const_get("Person").send("new")
person.class => Person

#then i have a method which returns a hash of attributes
get_person_attributes.each do |att|
  person.send("#{att}=", get_person_attributes[att])

person.inspect => #<Person ....> #all the attributes look ok here

now come the problems. firstly, i tried just doing
person.update_attributes(get_person_attributes), which results in:

`new_record?' for "Person":String

and doing gives the same error.

the models initialize method looks like:
def initialize(*args)
  ...other stuff

any ideas why i'm getting that error? I know update_attributes calls
save(), so they're the same problem, but i can't figure out what's
causing save to be called on the string object.

thanks for reading.

What's the backtrace like when this happens ?


May I ask why you’re using Kernel.const_get… what’s wrong with person = “Person”

Then person.new_record? works for me.