oo::util(n)
π oo::util β utility commands for TclOO, bestie edition π
okay so this is the oo::util(n) manual page, from the tcllib fam, and it's literally the little toolkit that makes TclOO way less annoying. grab a snack, we're going through all of it. no skips. π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require TclOO
package require oo::util ?1.2.3?
mymethod method ?arg...?
classmethod name arguments body
classvariable ?arg...?
link method...
link {alias method}...
ooutil::singleton ?arg...?
πΈ DESCRIPTION πΈ
okay so this package gives you a convenience command for specifying instance methods as callback commands. like, timers, file events, Tk bindings, all that stuff where you gotta hand a command prefix to something and walk away. it's giving "please just work when the callback fires" and honestly it does. β¨
π COMMANDS π
mymethod method ?arg...?β this one lives inside instance methods. you give it a method name and maybe some args for that method, and it hands you back a command prefix. when that prefix gets executed, it invokes the named method of the object you're in, with the args you provided plus any extra ones supplied at the moment of actual invocation. π«Ά
note: this command is equivalent to β and named after β the command that the OO package snit provides for the exact same purpose. iykyk.
classmethod name arguments bodyβ this one lives inside class definitions. it takes a method name, maybe some arguments for the method, and creates a method on the class, available to a user of the class and of derived classes. class methods, slay. π
note: this command is equivalent to thetypemethodcommand provided by the OO packagesnitfor the same purpose.
example π
oo::class create ActiveRecord {
classmethod find args { puts "[self] called with arguments: $args" }
}
oo::class create Table {
superclass ActiveRecord
}
puts [Table find foo bar]
# ======
# which will write
# ======
# ::Table called with arguments: foo bar
classvariable ?arg...?β also an instance-methods-only situation. you hand it a series of variable names and it makes them available in the method's scope. the originating scope for those variables is the class (instance) that the object instance belongs to. put differently: the referenced variables are shared between all instances of their class. so everybody's in the group chat together. π¬
note: this command is roughly equivalent to thetypevariablecommand provided by the OO packagesnitfor the same purpose. the difference? it cannot be used in the class definition itself. that's the catch bestie. π
example: β¨
% oo::class create Foo {
method bar {z} {
classvariable x y
return [incr x $z],[incr y]
}
}
::Foo
% Foo create a
::a
% Foo create b
::b
% a bar 2
2,1
% a bar 3
5,2
% b bar 7
12,3
% b bar -1
11,4
% a bar 0
11,5
link method...link {alias method}...β instance methods only, again. you pass it a list of method names and/or pairs of alias- and method-name, and it makes the named methods available to all instance methods without requiring themycommand. the alias name the method shows up under defaults to the method name, unless you explicitly gave an alias/method pair. π«
examples: π
link foo
# The method foo is now directly accessible as foo instead of my foo.
link {bar foo}
# The method foo is now directly accessible as bar.
link a b c
# The methods a, b, and c all become directly acessible under their
# own names.
the main use of this command is expected to be in instance constructors β for convenience β or to set up some methods for use in a mini DSL. cute little DSL setup, obsessed. π§
ooutil::singleton ?arg...?β this one is a meta-class, i.e. a variant of the builtinoo::classwhich ensures that it creates only a single instance of the classes defined with it. one and done. main character energy, no duplicates. πβ¨
syntax and results are like for oo::class.
example: π¦
% oo::class create example {
self mixin singleton
method foo {} {self}
}
::example
% [example new] foo
::oo::Obj22
% [example new] foo
::oo::Obj22
π AUTHORS π
Donal Fellows, Andreas Kupries
π BUGS, IDEAS, FEEDBACK π
so. this document, and the package it describes, will undoubtedly contain bugs and other problems. like, it's software, it's not that deep, but please do report them in the category oo::util of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. and please also report any ideas for enhancements you may have for either package and/or documentation. we want the ideas. give us the ideas. π
when proposing code changes, please provide unified diffs, i.e. the output of diff -u.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. periodt. π
π SEE ALSO π
π KEYWORDS π
TclOO, callback, class methods, class variables, command prefix, currying, method reference, my method, singleton
π CATEGORY π
Utility
β COPYRIGHT β
Copyright (c) 2011-2015 Andreas Kupries, BSD licensed
okay that's the whole page, you made it, I'm so proud of you π«Ά this was oo::util(n) from tcllib, version 1.2.3, and that's the vibe check complete. go write some class methods bestie, you got this πβ¨πΈ
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2011-2015 Andreas Kupries, BSD licensed
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms