--=-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 <ttmrichter / gmail.com> (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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
  <META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/3.12.1">
</HEAD>
<BODY>
So, I'm trying my hand at metaprogramming and am finding this the result of=
 executing my code with -w enabled:<BR>
<BR>
<TT><B>warning: class variable access from toplevel singleton method</B></T=
T><BR>
<BR>
(This is spammed ad infinitum anywhere I use the overridden gets, but it's =
always the same message and always the same cause: gets.)<BR>
<BR>
The code it's pointing to looks like this:<BR>
<BR>
<TT>def override_methods(io_in)</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts io_in</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class &lt;&lt; io_in</TT><BR=
>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; alias :old_gets :gets</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; @@override_buffer=3D[]</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; def gets separator =3D $/</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise A=
rgumentError, &quot;cannot use non-standard separator&quot; unless separato=
r =3D=3D $/</TT><BR>
<BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; end</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io_in</TT><BR>
<TT>end</TT><BR>
<BR>
<TT>def find_block_begin io_in</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io_in =3D override_methods(i=
o_in)</TT><BR>
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io_in.find_end</TT><BR>
<TT>end</TT><BR>
<BR>
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.&nbsp; My modified gets needs=
 access to that (shared) buffer that the added find_end method generates wh=
ile peeking ahead.&nbsp; @override_buffer and override_buffer don't work (t=
he latter for reasons obvious to me, the former ... not so obvious).<BR>
<BR>
Now, the output of the code is exactly what I expect it to be, so this isn'=
t a show-stopper.&nbsp; I am, however, in the habit of making my code -w cl=
ean if it's at all possible.&nbsp; How would I do it with that snippet?<BR>
<BR>
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
-- <BR>
<B>Michael T. Richter</B> &lt;<A HREF=3D"mailto:ttmrichter / gmail.com">ttmri=
chter / gmail.com</A>&gt; (<B>GoogleTalk:</B> ttmrichter / gmail.com)<BR>
<I>In his errors a man is true to type. Observe the errors and you will kno=
w the man. (&#23380;&#22827;&#23376;)</I>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

--=-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--