class BaseItem
def initialize(name)
@name = name
end
def add_tags(*tags)
tags.each do |mod|
mod.instance_variables.each do |iv|
var_name = iv.to_s
var_value = mod.instance_variable_get(var_name)
if instance_variable_get(var_name).class == Fixnum
instance_variable_set(var_name, (instance_variable_get(var_name) + var_value))
else
instance_variable_set(var_name, var_value)
end
end
end
end
end
module Sharp
@damage = 1
end
module Heavy
@weight = 3
@damage = 2
end
module Flaming
@damage = 3
end
class Weapon < BaseItem
def initialize(name)
super name
@damage = 1
end
end
sword = Weapon.new('Blade of Stuff')
sword.add_tags Sharp, Heavy, Flaming
Playing around with modules. The idea is that an object extended the Sharp module would have its damage incremented by 1. If the object doesnt contain the variable then it gets set on it. Make any sense? Wtf is wrong! =)