From: Robert Klemme Date: 2003-04-07T16:47:25+09:00 Subject: Re: To inherit or to include? That is the question. "Phil Tomson" schrieb im Newsbeitrag news:b6kqiu0uka@enews4.newsguy.com... > >The simples rule is that you have to use inheritance if you want to reuse > >state. Modules can only provide methods. So, if you have a set of > >related methods that can be expected to be used in different classes, put > >them together in a module. > > But this isn't quite true. You can create/manipulate instance variables > withing a modules's methods: > > module Foo > def set_var(v) > @var = v > end > def get_var > @var > end > end > > class Bar > include Foo > attr_accessor :var > end > > b = Bar.new > b.set_var(42) > puts b.var #-> 42 > > > So, the module Foo was able to introduce some state into the class Bar. Oops! Something learned again. Obviously I misread something. Maybe the difference then is that a module can't introduce state on initialization? robert