classvariable(n)
π NAME π
okay bestie, welcome to the classvariable(n) page from the TclOO Commands manual π . This one is literally classvariable β Create link from local variable to variable in class. No cap, that's the whole name.
β¨ SYNOPSIS β¨
the group-chat summoning spell is:
package require tcl::oo
classvariable variableName ?...?
πΈ DESCRIPTION πΈ
okay so here's the tea β:
- The
classvariablecommand is available within methods. That's its whole habitat. - It takes a series of one or more variable names and makes them available in the method's scope. Slay.
- Those variable names must not be qualified and must not refer to array elements. Like, keep it simple, bestie.
- The originating scope for the variables is the namespace of the class that the method was defined by. In other words, the referenced variables are shared between all instances of that class β¨. That's the main character energy right there.
Also, fun fact: this command is equivalent to the typevariable command provided by the snit package in tcllib for approximately the same purpose. Same vibe, different package π
.
If used in a method defined directly on a class instance (e.g., through the oo::objdefine method definition), this is very much like just using:
namespace upvar [namespace current] $var $var
for each variable listed to classvariable. iykyk.
π¦ EXAMPLE π¦
This class counts how many instances of it have been made. It's giving "counter era" and honestly? Obsessed.
oo::class create Counted {
initialise {
variable count 0
}
variable number
constructor {} {
classvariable count
set number [incr count]
}
method report {} {
classvariable count
puts "This is instance $number of $count"
}
}
set a [Counted new]
set b [Counted new]
$a report
β This is instance 1 of 2
set c [Counted new]
$b report
β This is instance 2 of 3
$c report
β This is instance 3 of 3
π SEE ALSO π
go read these when you're done, bestie:
global(n)namespace(n)oo::class(n)oo::define(n)upvar(n)variable(n)
π KEYWORDS π
class, class variable, variable β that's the keyword trio, periodt.
π TclOO 0.3 Β· classvariable(n) Β· no date listed, just vibes β¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- nixos 26.05: tcl 9.0.3
- Copyright (c) 2011-2015 Andreas Kupries
- Copyright (c) 2018 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms