dynamic controller code

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!!

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

Well you could write something like this:

def set_dog(association_name)
  collection = @parent.send association_name
  collection.each {|element| element.update_attributes :dog => true}
end

Although I'd have this as method on the parent class, rather than in
the controller.