From: Simen Date: 2006-05-03T03:33:18+09:00 Subject: Re: Mixin Syntax for Newbies Simen wrote: > Nathan Olberding wrote: >> Simen wrote: >>> In the above code, @one is actually an instance variable of module One: >>> >>> One.instance_variable_get "@one" >>> # => "One!" >> >> Okay, that makes sense. In that case, is it possible to have instance >> variables for classes defined in modules which they mix in? > > If you make it a method, you can call it from initialize: > > module One > def one; @one = "One!"; end > end > class Two > def initialize > one > puts @one > end > end > # Outputs "One!" > two = Two.new Whoops, you need to include One first: class Two include One ... end ( I gotta stop using the ruby-forum gateway. It's so easy it makes me sloppy ). -- Posted via http://www.ruby-forum.com/.