如何将一堆实例变量从一个对象添加到另一个对象?
例如,想象您拥有基础机器人的机器人,您可以使用附加组件对其进行自定义.
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