From: "Carlo E. Prelz" Date: 2013-02-03T18:43:42+09:00 Subject: Re: Storing string-data in a module Subject: Storing string-data in a module Date: dom 03 feb 13 06:12:20 +0900 Quoting Marc Heiler (lists@ruby-forum.com): > Now, however, I _also_ want to be able to store > this in the module. But how can I do this? I might be mistaken, but I believe you cannot. There are global variables (prepended by '$'), class variables (prepended by '@@') and instance variables (prepended by '@'). But there are, to my knowledge, no module variables. And this is exactly why modules are more flexible: they provide methods, but they do not provide instantiation or storage. From what I know, a module can only own constants (immutable). I believe this boils down to the usual multiple-inheritance-related class of FAQ's. IMO, Ruby's designers have decided to avoid multiple inheritance not because it is evil, but because the sheer amount of unescapable, tangled complexity brought in *at language implementation level* by multiple inheritance would produce a clumsier language as a whole. I back their decision single-heartedly. If I were facing your problem, I would pass the string as the first parameter to all functions in the module, like this: def one(string,i='') string+='<'+i+'>' end You can directly use the instance's variable, like this: def one(i = '') @string+='<'+i+'>' end @string would be owned by the instance of each class that included your module. But I think this last way obfuscates things a bit too much. Carlo -- * Se la Strada e la sua Virtu' non fossero state messe da parte, * K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)