<h1>self</h1>
<DL style="font-size:.85em">
<DD><A HREF="#M2" NAME="L1713">NAME</A>
<DL><DD>self &mdash; method call internal
<DD><A HREF="#M3" NAME="L1714">SYNOPSIS</A>
<DL>
</DL>
<DD><A HREF="#M4" NAME="L1715">DESCRIPTION</A>
<DL class="description">
<DD><A HREF="#M5" NAME="L1716"><B>self
<DD><A HREF="#M6" NAME="L1717"><B>self
<DD><A HREF="#M7" NAME="L1718"><B>self
<DD><A HREF="#M8" NAME="L1719"><B>self
<DD><A HREF="#M9" NAME="L1720"><B>self
<DD><A HREF="#M10" NAME="L1721"><B>self
<DD><A HREF="#M11" NAME="L1722"><B>self
<DD><A HREF="#M12" NAME="L1723"><B>self
<DD><A HREF="#M13" NAME="L1724"><B>self
</DL>
<DD><A HREF="#M14" NAME="L1725">EXAMPLES</A>
<DD><A HREF="#M15" NAME="L1726">SEE ALSO</A>
<DD><A HREF="#M16" NAME="L1727">KEYWORDS</A>
</DL>
<H3><A
<b>self</b> &mdash; method call internal introspection
<H3><A
package require TclOO<BR>
<BR>
<B>self</B> ?<I>subcommand</I>?<BR>
<H3><A
The <B>self</B> 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, <I>subcommand</I>, that tells it what sort of information is
actually desired; if omitted the result will be the same as if <B>self
object</B> was invoked. The supported subcommands are:
<P>
<DL class="description">
<DT><A NAME="M5"><B>self
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 <B><A HREF="?name=Doc:+info">info <B>call</B> for the current method (except that this
also reports useful values from within constructors and destructors, whose
names are reported as <B>&lt;constructor&gt;</B> and <B>&lt;destructor&gt;</B>
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).
<P><DT><A NAME="M6"><B>self
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
<B>&lt;constructor&gt;</B> and <B>&lt;destructor&gt;</B> indicating constructors and
destructors respectively).
<P><DT><A NAME="M7"><B>self
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 <B><A and that if the method was defined on an object then this
will fail.
<P>
If you want the class of the current object, you need to use this other
construct:
<P>
<PRE>info object class [<B>self
<P><DT><A NAME="M8"><B>self
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 <B>object</B> or <B>class</B> depending on whether the declaring entity
was an object or class, and the third element is the name of the filter.
<P><DT><A NAME="M9"><B>self
This returns the name of the current method (with the strings
<B>&lt;constructor&gt;</B> and <B>&lt;destructor&gt;</B> indicating constructors and
destructors respectively).
<P><DT><A NAME="M10"><B>self
This returns the name of the unique namespace of the object that the method
was invoked upon.
<P><DT><A NAME="M11"><B>self
When invoked from a method that is not at the end of a call chain (i.e. where
the <B><A 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 <B>&lt;constructor&gt;</B> and <B>&lt;destructor&gt;</B>
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.
<P><DT><A NAME="M12"><B>self
This returns the name of the object that the method was invoked upon.
<P><DT><A NAME="M13"><B>self
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.
<P></DL>
<H3><A
This example shows basic use of <B>self</B> to provide information about the
current object:
<P>
<PRE>oo::class create c {
    method foo {} {
        puts &quot;this is the [<B>self</B>] object&quot;
    }
}
c create a
c create b
a foo                <I><font size="+1">&#8594;</font> prints &quot;this is the ::a object&quot;</I>
b foo                <I><font size="+1">&#8594;</font> prints &quot;this is the ::b
<P>
This demonstrates what a method call chain looks like, and how traversing
along it changes the index into it:
<P>
<PRE>oo::class create c {
    method x {} {
        puts &quot;Cls: [<B>self call</B>]&quot;
    }
}
c create a
oo::objdefine a {
    method x {} {
        puts &quot;Obj: [<B>self call</B>]&quot;
        next
        puts &quot;Obj: [<B>self call</B>]&quot;
    }
}
a x     <I><font size="+1">&#8594;</font> Obj: {{method x object method} {method x ::c method}} 0</I>
        <I><font size="+1">&#8594;</font> Cls: {{method x object method} {method x ::c method}} 1</I>
        <I><font size="+1">&#8594;</font> Obj: {{method x object method} {method x ::c method}}
<H3><A NAME="M15">SEE
<B><A <B><A
<H3><A
call, introspection, object