M
MR Damien
hi,
I am trying to use some dynamic features of ruby.
Inside my module, I try to add some method dynamicaly but I get an error
when I am trying to.
module Rubyhaviour
def add(object)
name = "@" + object.class.downcase
if self.instance_variable_get(name)
self.instance_variable_get(name) << object
else
self.instance_variable_set(name, Array.new)
self.instance_variable_get(name) << object
define_method(name) do
instance_variable_get("@#{name}")
end
end
end
end
undefined method `define_method' for #<Test:0x2ce631c> (NoMethodError)
I am trying to use some dynamic features of ruby.
Inside my module, I try to add some method dynamicaly but I get an error
when I am trying to.
module Rubyhaviour
def add(object)
name = "@" + object.class.downcase
if self.instance_variable_get(name)
self.instance_variable_get(name) << object
else
self.instance_variable_set(name, Array.new)
self.instance_variable_get(name) << object
define_method(name) do
instance_variable_get("@#{name}")
end
end
end
end
undefined method `define_method' for #<Test:0x2ce631c> (NoMethodError)