M
Michael T. Richter
--=-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 ld_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 <[email protected]> (GoogleTalk:
(e-mail address removed))
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>  =
; alias ld_gets :gets</TT><BR>
<TT>  =
; @@override_buffer=3D[]</TT><BR>
<TT>  =
; def gets separator =3D $/</TT><BR>
<TT>  =
; raise A=
rgumentError, "cannot use non-standard separator" unless separato=
r =3D=3D $/</TT><BR>
<BR>
<TT>  =
; unless =
line =3D @@override_buffer.shift</TT><BR>
<TT>  =
; &n=
bsp; return old_gets</TT><BR>
<TT>  =
; else</T=
T><BR>
<TT>  =
; &n=
bsp; return line</TT><BR>
; end</TT><BR>
<TT>  =
; def find_end</TT><BR>
<TT>  =
; for a i=
n 1..20</TT><BR>
<TT>  =
; &n=
bsp; line =3D self.old_gets</TT><BR>
<TT>  =
; &n=
bsp; if line =3D=3D "__END__\n&quo=
t;</TT><BR>
<TT>  =
; &n=
bsp;  =
; @@override_buffer =3D []</TT><BR>
<TT>  =
; &n=
bsp;  =
; break</TT><BR>
<TT>  =
; &n=
bsp; else</TT><BR>
<TT>  =
; &n=
bsp;  =
; @@override_buffer << line</TT><BR>
<TT>  =
; &n=
bsp; end</TT><BR>
; self</T=
T><BR>
<TT>  =
; end</TT><BR>
<TT> end</TT><BR>
<TT> io_in</TT><BR>
<TT>end</TT><BR>
<BR>
<TT>def find_block_begin io_in</TT><BR>
<TT> io_in =3D override_methods(i=
o_in)</TT><BR>
<TT> 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. 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).<BR>
<BR>
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?<BR>
<BR>
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
-- <BR>
<B>Michael T. Richter</B> <<A HREF=3D"mailto:[email protected]">ttmri=
(e-mail address removed)</A>> (<B>GoogleTalk:</B> (e-mail address removed))<BR>
<I>In his errors a man is true to type. Observe the errors and you will kno=
w the man. (孔夫子)</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--
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 ld_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 <[email protected]> (GoogleTalk:
(e-mail address removed))
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>  =
; alias ld_gets :gets</TT><BR>
<TT>  =
; @@override_buffer=3D[]</TT><BR>
<TT>  =
; def gets separator =3D $/</TT><BR>
<TT>  =
; raise A=
rgumentError, "cannot use non-standard separator" unless separato=
r =3D=3D $/</TT><BR>
<BR>
<TT>  =
; unless =
line =3D @@override_buffer.shift</TT><BR>
<TT>  =
; &n=
bsp; return old_gets</TT><BR>
<TT>  =
; else</T=
T><BR>
<TT>  =
; &n=
bsp; return line</TT><BR>
<TT>  =<BR>
; end</TT><BR>
<TT>  =
; def find_end</TT><BR>
<TT>  =
; for a i=
n 1..20</TT><BR>
<TT>  =
; &n=
bsp; line =3D self.old_gets</TT><BR>
<TT>  =
; &n=
bsp; if line =3D=3D "__END__\n&quo=
t;</TT><BR>
<TT>  =
; &n=
bsp;  =
; @@override_buffer =3D []</TT><BR>
<TT>  =
; &n=
bsp;  =
; break</TT><BR>
<TT>  =
; &n=
bsp; else</TT><BR>
<TT>  =
; &n=
bsp;  =
; @@override_buffer << line</TT><BR>
<TT>  =
; &n=
bsp; end</TT><BR>
<TT>  =<BR>
; self</T=
T><BR>
<TT>  =
; end</TT><BR>
<TT> end</TT><BR>
<TT> io_in</TT><BR>
<TT>end</TT><BR>
<BR>
<TT>def find_block_begin io_in</TT><BR>
<TT> io_in =3D override_methods(i=
o_in)</TT><BR>
<TT> 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. 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).<BR>
<BR>
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?<BR>
<BR>
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
-- <BR>
<B>Michael T. Richter</B> <<A HREF=3D"mailto:[email protected]">ttmri=
(e-mail address removed)</A>> (<B>GoogleTalk:</B> (e-mail address removed))<BR>
<I>In his errors a man is true to type. Observe the errors and you will kno=
w the man. (孔夫子)</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--