oo::util(3tcl)
β¨ NAME β¨
oo::util β the little utility command pack for TclOO, aka the glow-up your classes were waiting for π
This is the <code>oo::util</code> manual page, section <code>3tcl</code>, bestie. Buckle up.
πΈ 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 hands you a convenience command so you can specify instance methods as callback commands, like, so easily. We're talking timers, file events, Tk bindings, etc. β all of it. β¨
π 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 you run that prefix, it invokes the named method of the object you're in β with the args you gave it plus any others that show up at the actual moment of invocation. It's giving currying, no cap. π
Note: this command is equivalent to β and literally 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. You hand it a method name, and possibly arguments for the method, and it creates a method on the class β available to a user of the class and of derived classes. Main character energy for your whole inheritance tree, fr fr. π
Note: this is equivalent to the typemethod command that the OO package snit provides for 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...?
This one lives inside instance methods. You give 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. Translation: those referenced variables are shared between all instances of their class. Bestie, they're literally sharing. π«Ά
Note: this is roughly equivalent to the typevariable command that the OO package snit provides for the same purpose. The difference? It cannot be used in the class definition itself. Important. Don't try it.
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}...
This one lives inside instance methods. You give it a list of method names and/or pairs of alias-name and method-name, and it makes the named methods available to all instance methods β no my command required. The audacity. Obsessed. π₯
The alias name under which the method becomes available defaults to the method name, except where you explicitly specify it through 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. Slay. π
π ooutil::singleton ?arg...?
This command is a meta-class β that is, a variant of the builtin oo::class which ensures that it creates only a single instance of the classes defined with it. One. Uno. Periodt. π
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 π
This document, and the package it describes, will undoubtedly contain bugs and other problems. Not me being dramatic, it's just the truth of all software. Please report such in the category oo::util of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. We want them. Give them to us. π
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. That's the whole trick, bestie. π
π 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
And that's the whole page, bestie β this was oo::util(3tcl) from <strong>tcllib</strong>, version <strong>1.2.3</strong>. Go forth and make some singletons. π¦β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- 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