D
Damjan Rems
What I am trying to accomplist is:
class MyClass
def addVar(var, val)
instance_variable_set("@#{var}", val)
define_method("#{var}") { || instance_variable_get("#{var}") }
end
end
c = MyClass.new
c.addVar('aa',10) # here pops the error
c.aa # should return 10
But I get this error:
NoMethodError: undefined method `define_method' for #<MyClass:0x2d01cc0
@aa=10>
from (irb):4:in `addVar'
from (irb):8
I know this should work because it's used all over rails.
Advice me please
TheR
class MyClass
def addVar(var, val)
instance_variable_set("@#{var}", val)
define_method("#{var}") { || instance_variable_get("#{var}") }
end
end
c = MyClass.new
c.addVar('aa',10) # here pops the error
c.aa # should return 10
But I get this error:
NoMethodError: undefined method `define_method' for #<MyClass:0x2d01cc0
@aa=10>
from (irb):4:in `addVar'
from (irb):8
I know this should work because it's used all over rails.
Advice me please
TheR