From: James Edward Gray II Date: 2005-12-07T23:30:33+09:00 Subject: Re: Mixins and variables On Dec 6, 2005, at 11:06 PM, Johannes Friestad wrote: > 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(). I see you have your answer, so let me just make some general comments: > Example: > ----------------- > module TestMod > def x > @x > end > def x=(arg) > @x=arg > end You can replace the last six lines with: attr_accessor :x > end > > class TestClass > include TestMod > def initialize > x=('alpha') self.x = 'alpha' # as discussed, or just @x = 'alpha' > printf("x=%s\n", x) And we would usually write that as: puts "x=#{x}" > end > end Hope that gives you an idea or two. James Edward Gray II