oo::util(3tcl) | Utility commands for TclOO | oo::util(3tcl) |
oo::util - Utility commands for TclOO
package require Tcl 8.5
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...?
This package provides a convenience command for the easy specification of instance methods as callback commands, like timers, file events, Tk bindings, etc.
Note: The command is equivalent to and named after the command provided by the OO package snit for the same purpose.
Note: The command is equivalent to the command typemethod provided by the OO package snit 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
Note: The command is roughly equivalent to the command typevariable provided by the OO package snit for the same purpose. The difference is that it cannot be used in the class definition itself.
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
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.
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
Donal Fellows, Andreas Kupries
This document, and the package it describes, will undoubtedly contain bugs and other problems. 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.
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.
snit(3tcl)
TclOO, callback, class methods, class variables, command prefix, currying, method reference, my method, singleton
Utility
Copyright (c) 2011-2015 Andreas Kupries, BSD licensed
1.2.2 | tcllib |