From: E S Date: 2005-01-18T09:07:45+09:00 Subject: Re: Fwd: [suby-ruby] Your all time desired fundemental Ruby mod > L�hett�j�: Yukihiro Matsumoto > Aihe: Re: Fwd: [suby-ruby] Your all time desired fundemental Ruby mod > > Hi, > > In message "Re: Fwd: [suby-ruby] Your all time desired fundemental Ruby mod" > on Mon, 17 Jan 2005 23:22:30 +0900, "trans. (T. Onoma)" writes: > > |I want to expand the functionality of this class with a module I have: > | > | module M > | def x ; @x ; end > | end > | > |But @x needs to default to an array. So what do I do? Presently I have two > |choices. Either change M to: > | > | module M > | def x ; @x ||= [] ; end > | end > | > |or use super as you suggest. But I don;t want to just recopy C for what if it > |changed internally later? > > Initializing module instance variables are one of the things I want to > fix. But I'm not sure what is the best way to fix. Maybe AOP-like > hooks is the way to go. I'm waiting the conviction to come. Does it need to be fixed? I don't think instance variables belong in a Module, conceptually. They can be put there, yes, it's just harder to get them in proper working order, which encourages 'proper' design but allows circumvention if necessary. I can't think of any situations where one would have no other option than instance variables in a Module. > matz. E