From: "Michael T. Richter" Date: 2007-08-02T21:46:23+09:00 Subject: What does this warning actually mean? --=-Tn+ojkiOZAo6sC2h3S19 Content-Type: multipart/alternative; boundary="=-EYlAYUk/EEJikpzkd0gn" --=-EYlAYUk/EEJikpzkd0gn Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable So, I'm trying my hand at metaprogramming and am finding this the result of executing my code with -w enabled: warning: class variable access from toplevel singleton method (This is spammed ad infinitum anywhere I use the overridden gets, but it's always the same message and always the same cause: gets.) The code it's pointing to looks like this: def override_methods(io_in) puts io_in class << io_in alias :old_gets :gets @@override_buffer=3D[] def gets separator =3D $/ raise ArgumentError, "cannot use non-standard separator" unless separator =3D=3D $/ unless line =3D @@override_buffer.shift return old_gets else return line end end def find_end for a in 1..20 line =3D self.old_gets if line =3D=3D "__END__\n" @@override_buffer =3D [] break else @@override_buffer << line end end self end end io_in end def find_block_begin io_in io_in =3D override_methods(io_in) io_in.find_end end To me the culprit is likely that @@override_buffer thing, but I can't for the life of me figure out how to get around it. My modified gets needs access to that (shared) buffer that the added find_end method generates while peeking ahead. @override_buffer and override_buffer don't work (the latter for reasons obvious to me, the former ... not so obvious). Now, the output of the code is exactly what I expect it to be, so this isn't a show-stopper. I am, however, in the habit of making my code -w clean if it's at all possible. How would I do it with that snippet? --=20 Michael T. Richter (GoogleTalk: ttmrichter@gmail.com) In his errors a man is true to type. Observe the errors and you will know the man. (=E5=AD=94=E5=A4=AB=E5=AD=90) --=-EYlAYUk/EEJikpzkd0gn Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable So, I'm trying my hand at metaprogramming and am finding this the result of= executing my code with -w enabled:

warning: class variable access from toplevel singleton method

(This is spammed ad infinitum anywhere I use the overridden gets, but it's = always the same message and always the same cause: gets.)

The code it's pointing to looks like this:

def override_methods(io_in)
        puts io_in
        class << io_in             = ;    alias :old_gets :gets
            = ;    @@override_buffer=3D[]
            = ;    def gets separator =3D $/
            = ;            raise A= rgumentError, "cannot use non-standard separator" unless separato= r =3D=3D $/

            = ;            unless = line =3D @@override_buffer.shift
            = ;            &n= bsp;       return old_gets
            = ;            else
            = ;            &n= bsp;       return line
            = ;            end
            = ;    end
            = ;    def find_end
            = ;            for a i= n 1..20
            = ;            &n= bsp;       line =3D self.old_gets
            = ;            &n= bsp;       if line =3D=3D "__END__\n&quo= t;
            = ;            &n= bsp;            = ;   @@override_buffer =3D []
            = ;            &n= bsp;            = ;   break
            = ;            &n= bsp;       else
            = ;            &n= bsp;            = ;   @@override_buffer << line
            = ;            &n= bsp;       end
            = ;            end
            = ;            self
            = ;    end
        end
        io_in
end

def find_block_begin io_in
        io_in =3D override_methods(i= o_in)
        io_in.find_end
end

To me the culprit is likely that @@override_buffer thing, but I can't for t= he life of me figure out how to get around it.  My modified gets needs= access to that (shared) buffer that the added find_end method generates wh= ile peeking ahead.  @override_buffer and override_buffer don't work (t= he latter for reasons obvious to me, the former ... not so obvious).

Now, the output of the code is exactly what I expect it to be, so this isn'= t a show-stopper.  I am, however, in the habit of making my code -w cl= ean if it's at all possible.  How would I do it with that snippet?

--
Michael T. Richter <ttmri= chter@gmail.com> (GoogleTalk: ttmrichter@gmail.com)
In his errors a man is true to type. Observe the errors and you will kno= w the man. (孔夫子)
--=-EYlAYUk/EEJikpzkd0gn-- --=-Tn+ojkiOZAo6sC2h3S19 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBGsdIZLqyWkKVQ54QRAs+lAJ0eWYi5gR8BOxLURrqmolgGEeIfFwCg2TrB X0GcRxEMzw5PzWol68NhL9k= =Y0D4 -----END PGP SIGNATURE----- --=-Tn+ojkiOZAo6sC2h3S19--