Tk and -w

Generally I expect modules not to generate warnings, but I get a whole
screenfull of the following using Ruby/Tk:

/usr/lib/ruby/1.6/tk.rb:233: warning: instance variable @cmdtbl not
initialized
/usr/lib/ruby/1.6/tk.rb:233: warning: instance variable @cmdtbl not
initialized
/usr/lib/ruby/1.6/tk.rb:233: warning: instance variable @cmdtbl not
initialized
/usr/lib/ruby/1.6/tk.rb:233: warning: instance variable @cmdtbl not
initialized
/usr/lib/ruby/1.6/tk.rb:233: warning: instance variable @cmdtbl not
initialized

The offending line reads:

@cmdtbl = [] unless @cmdtbl

Which seems like a sensible thing for Tk to do, especially since the next
line attempts a @cmdtbl.push.

Anything I can do about this warning?

Thanks.

-michael

···

++++++++++++++++++++++++++++++++++++++++++
Michael C. Libby x@ichimunki.com
public key: http://www.ichimunki.com/public_key.txt
web site: http://www.ichimunki.com
++++++++++++++++++++++++++++++++++++++++++

[…]

The offending line reads:

@cmdtbl = unless @cmdtbl
[…]

Anything I can do about this warning?

Either of the following two alternatives should work:

@cmdtbl = [] unless defined? @cmdtbl
@cmdtbl ||= []

Hope this helps.

		Reimer Behrends
···

michael libby (x@ichimunki.com) wrote:

The offending line reads:
@cmdtbl = unless @cmdtbl

Either of the following two alternatives should work:
@cmdtbl = unless defined? @cmdtbl

Thanks. This works perfectly. My tk code is much quieter now.

How to submit the following as a patch? The tk.rb in CVS appears to still
have the code that will generate a warning.

chandler@greyhound:/usr/lib/ruby/1.6$ diff tk.old.rb tk.rb
233c233
< @cmdtbl = unless @cmdtbl


···

On Wednesday 28 August 2002 03:23, Reimer Behrends wrote:

michael libby (x@ichimunki.com) wrote:
@cmdtbl = unless defined? @cmdtbl

++++++++++++++++++++++++++++++++++++++++++
Michael C. Libby x@ichimunki.com
public key: http://www.ichimunki.com/public_key.txt
web site: http://www.ichimunki.com
++++++++++++++++++++++++++++++++++++++++++