From: darren kirby Date: 2006-08-21T07:00:30+09:00 Subject: Re: [QUIZ] QAPrototype (#91) --nextPart64258123.GJMuTItW9Z Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline quoth the Matt Todd: > @Darren: > > Actually, you can declare an attr in the module and it will work as an > instance variable in the class it's mixed in. For example: > > module QAPrototype > attr :_methods_added > end > > That's what I did. Thanks for the tip. I was reading the section on mixins in the pickaxe book= ,=20 and tried doing it with an instance variable, but the code examples led me = to=20 believe that the attribute could only be set/read within the including clas= s=20 itself. Coupled with the fact that I was getting "No method '[]' for=20 Nil:Nilclass" (which I gather now was unrelated) I settled on the global=20 solution... > Also, print does work with one liners, but you need to flush out the > buffer each time you print the one line with > $stdout.flush. (Thanks to to cool folks in #ruby-lang for > that info.) What I mean here is that after I split the string which describes the metho= d=20 to an array for pretty printing my subscripting only works if the method=20 definition is 2+ lines of code (the 'def foo' and 'end' lines are freebies)= ,=20 to make a total of 4+... =20 An artificial limitation I know, I will fix it when I add consideration for= =20 method args. After reading a couple other solutions it seems much easier to= =20 add this than I had imagined. As for #ruby-lang, I have to agree. Someone in there saved my bacon too... Coming from more of a Python background, my first instinct to tackle this=20 problem was to overload/redefine the "NoMethodError" exception to get it to= =20 run my code. This, of course, didn't get me far, and I was directed=20 to "method_missing". I guess I should just read the built in/standard lib docs strait through so= I=20 will get a sense of what all methods are available... =20 =2Dd =2D-=20 darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." =2D Dennis Ritchie and Ken Thompson, June 1972 --nextPart64258123.GJMuTItW9Z Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQBE6NtvwPD5Cr/3CJgRAn5VAJwNNsO+E18aYsWnJAhN8wwdWIhf4wCdFEyJ LyCnhUlEa7FmUITx1vpPum8= =nr3s -----END PGP SIGNATURE----- --nextPart64258123.GJMuTItW9Z--