is it possible to dynamically create controller code??
for example if you have a parent element @parent and children element @parent.daughter and @parent.son.
@parent.daughter.class = daughter @parent.son.class = son
so if we wanted to add a dog to all of our sons or all of our daughters when a controller element is called we would have to do something like this.
def dog if @child.class == son for son in @parent.sons son.dog = true son.save! end else for daughter in @parent.daughters daughter.dog = true daughter.save! end end end
Duplicating code like this is annoying and not very DRY is anything like this remotely possible instead ??
def dog child_type = @child.class for child_type in @parent.child_type+s child_type.dog = true child_type.save! end end
this would cut code almost in half, for this situation. If there is anything capable of dynamically generating controller code based on object classes or even defined variables please let me know!!