J
Johannes Friestad
Hi,
I'm new to Ruby, and trying to figure out how the inheritance/mixin works:
I can't figure out how to set an instance variable with a mixin method
from the object's initialize().
Example:
-----------------
module TestMod
def x
@x
end
def x=3D(arg)
@x=3Darg
end
end
class TestClass
include TestMod
def initialize
x=3D('alpha')
printf("x=3D%s\n", x)
end
end
irb(main)..>tmp=3DTestClass.new
x=3Dalpha # x is set inside constructor
=3D> #<TestClass:0x37d9520>
irb(main)..>tmp.x
=3D> nil # x is unset on the returned object
I'm new to Ruby, and trying to figure out how the inheritance/mixin works:
I can't figure out how to set an instance variable with a mixin method
from the object's initialize().
Example:
-----------------
module TestMod
def x
@x
end
def x=3D(arg)
@x=3Darg
end
end
class TestClass
include TestMod
def initialize
x=3D('alpha')
printf("x=3D%s\n", x)
end
end
irb(main)..>tmp=3DTestClass.new
x=3Dalpha # x is set inside constructor
=3D> #<TestClass:0x37d9520>
irb(main)..>tmp.x
=3D> nil # x is unset on the returned object