# Tk special variables

**URL:** <https://www.ruby-forum.com/t/tk-special-variables/87558>\
**Category:** Ruby\
**Created:** [March 3, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/tk-special-variables/87558 "2007-03-03T21:38:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [March 3, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/tk-special-variables/87558/1 "2007-03-03T21:38:46Z")

</div>

How does one refer to a tk special variable in Ruby? In Perl, it is  
$Tk::. What tk special variables are available in Ruby? I’m  
referring to variables like patchLevel, strictMotif, VERSION and  
version.

In /usr/lib/ruby/1.8/tk.rb, I found TCL\_VERSION, TCL\_PATCHLEVEL,  
TCL\_MAJOR\_VERSION, TCL\_MINOR\_VERSION, TK\_VERSION, TK\_PATCHLEVEL,  
TK\_MAJOR\_VERSION, TK\_MINOR\_VERSION and JAPANIZED\_TK. This may be what  
I’m looking for, but these are constants, not variables.

When I try to refer to them (in irb), but after saying  
require ‘tk’  
I have tried as many different ways as I can…  
puts tk::TK\_VERSION  
puts TK\_VERSION  
puts TK::TK\_VERSION

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [March 3, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/tk-special-variables/87558/2 "2007-03-03T22:02:47Z")

</div>

Alle sabato 3 marzo 2007, Alan L. ha scritto:

> When I try to refer to them (in irb), but after saying  
> require ‘tk’  
> I have tried as many different ways as I can…  
> puts tk::TK\_VERSION  
> puts TK\_VERSION  
> puts TK::TK\_VERSION

I know nothing of tk, but the constants you looked for are in module Tk,  
not  
TK and not tk (which can’t be a module name since it doesn’t begin with  
an  
uppercase character). So, you should do:

require ‘tk’  
puts Tk::TK\_VERSION  
…

Looking at the names of the variables you mentioned (keeping in mind  
that I  
don’t know tk), I think there’s a good reason for which they’re  
constants:  
for instance, TK\_VERSION is the version of tk you have on your system,  
so I  
can’t think of a reason to change them.

By the way, to get the names of the constants (including classes and  
modules)  
defined in a class or module, you can use the constants method of the  
Module  
class. If you call it as a class method of the module class (i.e  
Module.constants), it will return an array with the top-level constants.  
If  
you call it as an instance method of a class / module it will return the  
names of the constants defined in it. In your case:

require ‘tk’  
Module.constants.sort  
=\> [“ARGF”, “ARGV”, “ArgumentError”, “Array”, …, “Tk”, “TkAfter”, …]

This tells you the module you needed is called Tk. To know the constants  
defined in the Tk module, you can do:

Tk.constants.sort  
=\> [“AUTO\_PATH”, “BinaryString”, …, “TK\_PATCHLEVEL”, “TK\_VERSION”,  
…]

I hope this helps

Stefano
