Hidetoshi NAGAI wrote:
> From: Edwin Fine <efine145-nospam01 / usa.net>
> Subject: Re: tk.rb warning in Turtle Graphics (#104)
> Date: Sat, 2 Dec 2006 17:03:13 +0900
> Message-ID: <26e18cd66a293ea06332d951983f9db6 / ruby-forum.com>
>> warnings). These consisted of the following two warnings:
>> 
>> /usr/lib/ruby/1.8/tk.rb:2313: warning: redefine encoding=
>> /usr/lib/ruby/1.8/tk.rb:2316: warning: redefine encoding
>> 
>> followed by 27,688 repetitions of this warning:
>> 
>> /usr/lib/ruby/1.8/tk.rb:1187: warning: instance variable @encoding not 
>> initialized
> 
> Don't worry about those. Those are no problem.
> 
> Redefinition of TclTkLib.encoding and encoding= depends on
> the difference between using 'tcltklib.so' only and with 'tk.rb'.
> 
> @encoding is used to check the encoding of a string.
> It depends that the value of non-initialized instance varible is nil.
> Of course, if check the existence of the variable first,
> the warning will be removed.
> But then, checking a string to pass to a Tcl/Tk interpreter needs
> two steps (check and refer).
> Such check is called very frequently. So, I ignored the warning.
-------------
Well, I found a bizarre and (to me) totally inexplicable way to get rid 
of the warning. This is from the quiz turtle_view.rb file. Adding an 
explicit return value (any value; I used nil) to the draw method gets 
rid of the warning. WTF???

   # Transform the turtle's track into TkcLine objects and add them to 
the
   # canvas' display list. This method expects a track to be an array of
   # the form
   #     track ::= [segment, segment, ...]
   #     segment ::= [point, point, ...]
   #     point ::= [x, y]
   # where x and y are floats.
   def draw
     @turtle.track.each do |seqment|
        if seqment.size > 1
           pts = seqment.collect { |pt| transform(pt) }
           TkcLine.new(@canvas, pts)
        end
     end
     nil # Adding this (or any return value) stops that @encoding 
warning
   end

I just dunno. Weird.

-- 
Posted via http://www.ruby-forum.com/.