Content-type: text/html Manpage of self

self

Section: TclOO Commands (n)
Updated: 0.1
Index Return to Main Contents



 

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 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 or object that the current method was defined within. Note that this will change as the chain of method implementations is traversed with next.
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 emtpy 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"

 

SEE ALSO

info(n), next(n)  

KEYWORDS

call, introspection, object


 

Index

NAME
SYNOPSIS
DESCRIPTION
EXAMPLES
SEE ALSO
KEYWORDS

This document was created by man2html, using the manual pages.
Time: 03:11:57 GMT, April 23, 2009