How can I add a bunch of instance variables from one object to another?
For example, imagine robots where you have the base robot and you can customize it with add-ons.
class Robot
def initialize
@name = "simple robot"
@power = nil #no power
@speed = nil
# more attributes
end
def add_attributes(addon)
@power = addon.power
@speed = addon.speed
#the rest of the attributes that addon has
end
end
I would like to re-write the add_attributes method to simply iterate over each of the addon's attributes instead of writing them all one by one, cause there could be dozens of attributes.
Some addons may have instance variables that Robot doesn't have, and I would also like to add them to Robot. Like creating instance variables on the fly?