oo::util(n) Utility commands for TclOO oo::util(n)______________________________________________________________________________NAME
oo::util - Utility commands for TclOO
SYNOPSIS
package require Tcl 8.5
package require TclOO
package require oo::util ?1.1?
mymethod method ?arg...?
classmethod name arguments body
classvariable ?arg...?
ooutil::singleton ?arg...?
_________________________________________________________________DESCRIPTION
This package provides a convenience command for the easy specification
of instance methods as callback commands, like timers, file events, Tk
bindings, etc.
COMMANDS
mymethod method ?arg...?
This command is available within instance methods. 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, and
any others supplied at the time of actual invokation.
Note: The command is equivalent to and named after the command
provided by the OO package snit for the same purpose.
classmethod name arguments body
This command is 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: The command is equivalent to the command typemethod pro‐
vided 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
classvariable ?arg...?
This command is available within instance methods. 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.
Note: The command is roughly equivalent to the command typevari‐
able 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
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.
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. Please report such in the category oo::util
of the Tcllib SF Trackers [http://source‐
forge.net/tracker/?group_id=12883]. Please also report any ideas for
enhancements you may have for either package and/or documentation.
SEE ALSOsnit(n)KEYWORDS
TclOO, callback, class methods, class variables, command prefix, curry‐
ing, method reference, my method, singleton
CATEGORY
Utility
COPYRIGHT
Copyright (c) 2011-2013 Andreas Kupries, BSD licensed
ooutil 1.1 oo::util(n)