oo::util(3tcl)
β¨ oo::util β the TclOO glow-up pack π
okay bestie, we're in the oo::util(3tcl) manual page and honestly? it's giving convenience. it's a whole little toolbox of utility commands for TclOO so your object-oriented Tcl life is cute and not chaotic. π
πΈ NAME πΈ
oo::util β Utility commands for TclOO. periodt. that's the whole name, that's the whole vibe.
π¦ SYNOPSIS π¦
package require Tcl 8.5 9
package require TclOO
package require oo::util ?1.2.2?
mymethod method ?arg...?
classmethod name arguments body
classvariable ?arg...?
link method...
link {alias method}...
ooutil::singleton ?arg...?
π DESCRIPTION π
so this package hands you a convenience command for the easy specification of instance methods as callback commands. like timers. like file events. like Tk bindings. like etc. you know the ones β the callback situation. no cap, that's what it's here for. π«Ά
π COMMANDS π
mymethod method ?arg...?
This one is available within instance methods (iykyk). it takes a method name and, possibly, arguments for the method, and returns a command prefix which β when executed β will invoke the named method of the object we are in, with the provided arguments, plus any others supplied at the time of actual invokation. π«
Note: this command is equivalent to and named after the command provided by the OO package snit for the same purpose. iconic behavior honestly.
classmethod name arguments body
Available within class definitions. it takes a method name and, possibly, arguments for the method and creates a method on the class, available to a user of the class and of derived classes. β¨
Note: this command is equivalent to the commandtypemethodprovided 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...?
Available within instance methods too. it takes a series of variable names and makes them available in the method's scope. the originating scope for the variables is the class (instance) the object instance belongs to. in other words, the referenced variables are shared between all instances of their class. bestie that's shared state, be normal about it π
Note: this command is roughly equivalent to the commandtypevariableprovided by the OO packagesnitfor the same purpose. the difference is that it cannot be used in the class definition itself. not the vibe, not allowed.
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}...
Available within instance methods. it takes a list of method names and/or pairs of alias- and method-name, and makes the named methods available to all instance methods without requiring the my command. the freedom of it all πβ¨
the alias name under which the method becomes available defaults to the method name, except where explicitly specified 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. main character energy fr fr. π
ooutil::singleton ?arg...?
this command is a meta-class, i.e. a variant of the builtin oo::class which ensures that it creates only a single instance of the classes defined with it. one (1) instance. that's it. that's the whole girl. π
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 π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. like, obviously. please report such in the category oo::util of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. please also report any ideas for enhancements you may have for either package and/or documentation. we want the ideas, we want the lore. π
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. don't inline the patch bestie i'm begging π
π 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 came out of tcllib, version 1.2.2, and the page itself is oo::util(3tcl) β go forth and curry your callbacks, you absolute icon π«Άβ¨π
π¦ 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