Hi everyone,
I am trying to extend an active record model using obj.extend(module).
The aim is to overwrite some of the model methods depending on what’s in
the object. For example, the base class would be “file”, with objects
such as “image”, and “text”.
The aim is to be able to something like this:
file = File.new()
file.extend(Image)
file.process <-- does image processing from the Image module
or:
file = File.new()
file.extend(Text)
file.process <-- does text processing from the Text module
I’m having trouble working out where the file.extend(xxxxx) should go -
I’d like to be able to load the object, check it’s type, and then extend
with the appropriate module. I’ve tried using initialize in the
activerecord class, but it doesn’t seem to be called when a new model
instance is created. Any ideas?
thanks,
Dan