From: Trans Date: 2007-06-16T13:39:30+09:00 Subject: Re: Using extend for initialization settings? On Jun 15, 11:46 pm, Trans wrote: > On Jun 15, 4:35 pm, Robert Klemme wrote: > > > > > > > > > > Hmm... I think maybe my point is being missed. The goal is to > > > initialize a class, not create a simple data struct. > > > Actually your code is about initializing an instance - not a class. > > Basically you just transform a Hash into some other data structure, a > > module with constant accessors in your case. At the moment I fail to > > see the benefit over something like this: > > > class Hash > > def init(x) > > each do |var, val| > > x.send("#{var}=", val) > > end > > end > > end > > > class Foo > > def initialize(settings) > > settings.init(self) > > end > > end > > > I find the approach using a module somewhat convoluted. Also a module > > simply does not seem the right vehicle IMHO. For example, what happens > > to attr_accessors that you define in that class? Either they override > > your anonymous module's methods or the other way round. This does not > > seem a good solution to me. > Attrsibutes would have precedence with how things work now. But that > is an interesting point. Not that we have this in Ruby presently, but > a #prepend instead of #extend could override attrs and would even > allow pre-object AOP. Sorry. I was thingk of #include, not #extensd. So scratch that ... reverse it. The extension overrides the attributes. So one _can_ do PER-object AOP with this. T.