self
NAMESYNOPSIS
DESCRIPTION
EXAMPLES
SEE ALSO
KEYWORDS
___________________________
NAME
self − method call internal introspection
SYNOPSIS
package require TclOO
self ?subcommand? ___________________________
DESCRIPTION
The self
command, which should only be used from within the context
of a call to a method (i.e. inside a method, constructor or
destructor body) is used to allow the method to discover
information about how it was called. It takes an argument,
subcommand, that tells it what sort of information is
actually desired; if omitted the result will be the same as
if self object was invoked. The supported subcommands
are:
self call
This returns a two-element list describing the method implementations used to implement the current call chain. The first element is the same as would be reported by info object call for the current method (except that this also reports useful values from within constructors and destructors, whose names are reported as <constructor> and <destructor> respectively), and the second element is an index into the first element’s list that indicates which actual implementation is currently executing (the first implementation to execute is always at index 0).
self caller
When the method was invoked from inside another object method, this subcommand returns a three element list describing the containing object and method. The first element describes the declaring object or class of the method, the second element is the name of the object on which the containing method was invoked, and the third element is the name of the method (with the strings <constructor> and <destructor> indicating constructors and destructors respectively).
self class
This returns the name of the class that the current method was defined within. Note that this will change as the chain of method implementations is traversed with next, and that if the method was defined on an object then this will fail.
If you want the class of the current object, you need to use this other construct:
info object class [self object]
self filter
When invoked inside a filter, this subcommand returns a three element list describing the filter. The first element gives the name of the object or class that declared the filter (note that this may be different from the object or class that provided the implementation of the filter), the second element is either object or class depending on whether the declaring entity was an object or class, and the third element is the name of the filter.
self method
This returns the name of the current method (with the strings <constructor> and <destructor> indicating constructors and destructors respectively).
self namespace
This returns the name of the unique namespace of the object that the method was invoked upon.
self next
When invoked from a method that is not at the end of a call chain (i.e. where the next command will invoke an actual method implementation), this subcommand returns a two element list describing the next element in the method call chain; the first element is the name of the class or object that declares the next part of the call chain, and the second element is the name of the method (with the strings <constructor> and <destructor> indicating constructors and destructors respectively). If invoked from a method that is at the end of a call chain, this subcommand returns the empty string.
self object
This returns the name of the object that the method was invoked upon.
self target
When invoked inside a filter implementation, this subcommand returns a two element list describing the method being filtered. The first element will be the name of the declarer of the method, and the second element will be the actual name of the method.
EXAMPLES
This example shows basic use of self to provide information about the current object:
oo::class
create c {
method foo {} {
puts "this is the [self] object"
}
}
c create a
c create b
a foo → prints "this is the ::a
object"
b foo → prints "this is the ::b
object"
This demonstrates what a method call chain looks like, and how traversing along it changes the index into it:
oo::class
create c {
method x {} {
puts "Cls: [self call]"
}
}
c create a
oo::objdefine a {
method x {} {
puts "Obj: [self call]"
next
puts "Obj: [self call]"
}
}
a x → Obj: {{method x object method} {method x ::c
method}} 0
→ Cls: {{method x object method} {method x ::c method}}
1
→ Obj: {{method x object method} {method x ::c method}}
0
SEE ALSO
KEYWORDS
call, introspection, object
More Linux Commands
manpages/frexp.3.html
frexp(3) - convert floating-point number to fractional and i
The frexp() function is used to split the number x into a normalized fraction and an exponent which is stored in exp. RETURN VALUE The frexp() function returns
manpages/randpkt.1.html
randpkt(1) - Random Packet Generator - Linux manual page....
randpkt is a small utility that creates a pcap trace file full of random packets. By creating many randomized packets of a certain type, you can test packet sni
manpages/remove_members.8.html
remove_members(8) - Remove members from a list. (Man Page)
remove_members [options] listname [addr1 ...] OPTIONS f file, file=file Remove member addresses found in the given file. If file is -, read stdin. a, ....(Man)
manpages/latin10.7.html
latin10(7) - ISO 8859-16 character set encoded in octal, dec
The ISO 8859 standard includes several 8-bit extensions to the ASCII character set (also known as ISO 646-IRV). ISO 8859-16, the Latin Alphabet No. 10 is used t
manpages/atanhl.3.html
atanhl(3) - inverse hyperbolic tangent function (Man Page)
The atanh() function calculates the inverse hyperbolic tangent of x; that is the value whose hyperbolic tangent is x. RETURN VALUE On success, these functions r
manpages/glGetPixelMapfv.3gl.html
glGetPixelMapfv(3gl) - return the specified pixel map.......
See the glPixelMap reference page for a description of the acceptable values for the map parameter. glGetPixelMap returns in values the contents of the pixel ma
manpages/optionSaveFile.3.html
optionSaveFile(3) saves the option state to a file..........
This routine will save the state of option processing to a file. The name of that file can be specified with the argument to the --save-opts option, or by appen
manpages/glutInitDisplayMode.3.html
glutInitDisplayMode(3) - sets the initial display mode......
The initial display mode is used when creating top-level windows, subwindows, and overlays to determine the OpenGL display mode for the to-be-created window or
manpages/mattrib.1.html
mattrib(1) - change MSDOS file attribute flags (Man Page)...
Mattrib is used to change MS-DOS file attribute flags. It has the following syntax: mattrib [-a|+a] [-h|+h] [-r|+r] [-s|+s] [-/] [-p] [-X] msdosfile [ msdosfile
manpages/fstatvfs.2.html
fstatvfs(2) - get file system statistics - Linux man page...
The function statvfs() returns information about a mounted filesystem. path is the pathname of any file within the mounted filesystem. buf is a pointer to a sta
manpages/glNormal3bv.3gl.html
glNormal3bv(3gl) - set the current normal vector (Man Page)
The current normal is set to the given coordinates whenever glNormal is issued. Byte, short, or integer arguments are converted to floating-point with a linear
manpages/tc-cbq-details.8.html
tc-cbq-details(8) - Class Based Queueing - Linux man page...
tc-cbq-details.8 - Class Based Queueing is a classful qdisc that implements a rich linksharing hierarchy of classes. It contains shaping elements as well as pri
