From: Hugh Sasse Staff Elec Eng Date: 2001-11-28T04:29:50+09:00 Subject: [ruby-talk:26691] Re: adding instance variables to an existing class. On Wed, 28 Nov 2001, David Alan Black wrote: > Hello -- > > Hmmm.... I must be writing/testing the wrong thing. Here's > what I wrote: > > class String > attr_writer :pos > def pos > @pos ||= 0 > end > > def thing(start = pos) > start > end > end > > p "hi".thing # => 0 > p "bye".pos # => 0 > > > Where do you get nil? I got a warning I missed last time! -- I had test_any and test_many -- or thought I did. Test_many turned out to be called test_any, so I in effect had: def thing(start = @pos) start end which was giving me the error. The warning was telling me about the redefinition. all is working well now. Thank you for your help and patience. OK (2/2 tests 13 asserts) :-) Hugh > > > David > > --