## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > my

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

my, myclass — 現在の対象又はその級のどの手段でも起動する Invoke any method of current object or its class

### 構文 説明 SYNOPSIS

package require tcl::oo
my methodName ?arg ...?
myclass methodName ?arg ...?

### DESCRIPTION

この my 命令は対象(又はその級)の手段を起動する為の対象の手段を許容する為に使われる､又､myclass 命令は､対象の現在の級の手段を起動する為に対象の手段を許容する為に使われる｡特に､ methodName の為の適切な値の組は､対象とその上位の組に運営されている全ての手段の組であり､移送されないものと､その対象か級に定義された他の手段内部で使われる時には､対象又は級の私的手段を含む｡ The my command is used to allow methods of objects to invoke methods of the object (or its class), and the myclass command is used to allow methods of objects to invoke methods of the current class of the object as an object. In particular, the set of valid values for methodName is the set of all methods supported by an object and its superclasses, including those that are not exported and private methods of the object or class when used within another method defined by that object or class.

その上で手段が my 経由で起動される対象は､初期にその中に my 命令が含まれる(註意: 命令が名称変更されていると連結が残る)名前空間を所有しているものであり､それは無為設定では現在起動された対象である｡同様に､その上で手段が myclass 経由で起動される対象は､対象の現在の級であり myclass 命令が初期に含まれていた名前空間を所有する対象である｡my と同様に､縦え命令が他の名前空間内に名称変更されても､連結は残り､無為設定で､現在の対象の級に生産されている｡ The object upon which the method is invoked via my is the one that owns the namespace that the my command is contained in initially (NB: the link remains if the command is renamed), which is the currently invoked object by default. Similarly, the object on which the method is invoked via myclass is the object that is the current class of the object that owns the namespace that the myclass command is contained in initially. As with my, the link remains even if the command is renamed into another namespace, and defaults to being the manufacturing class of the current object.

それぞれの対象は自己の my と myclass 命令を所有し､その名前空間の具現値内に含まれている｡ Each object has its own my and myclass commands, contained in its instance namespace.

### 用例 EXAMPLES

この用例は oo::object の 変数手段を使う為の my の基本的使用を示す､これは無為設定では公的には可視ではない: This example shows basic use of my to use the variables method of the oo::object class, which is not publicly visible by default:

    oo::class create c {
        method count {} {
            my variable counter
            puts [incr counter]
        }
    }

    c create o
    o count              → prints "1"
    o count              → prints "2"
    o count              → prints "3"

この用例は､正しい文脈に入る為の namespace code 命令を使用して､対象の外部から(trace から)私的手段に呼戻しさせる為に使用者が my を如何に使うかを示す｡(これを行うのに推奨された callback 命令を参照されたい｡) This example shows how you can use my to make callbacks to private methods from outside the object (from a trace), using namespace code to enter the correct context. (See the callback command for the recommended way of doing this.)

    oo::class create HasCallback {
        method makeCallback {} {
            return [namespace code {
                my Callback
            }]
        }

        method Callback {args} {
            puts "callback: $args"
        }
    }

    set o [HasCallback new]
    trace add variable xyz write [$o makeCallback]
    set xyz "called"     → prints "callback: xyz {} write"

項用例は その級の具現値から級の私的手段を如何に利用するかを例示する(これを行う為の更に高い水準の対話機能に関する oo::define 内の classmethod を参照されたい｡) This example shows how to access a private method of a class from an instance of that class. (See the classmethod declaration in oo::define for a higher level interface for doing this.)

    oo::class create CountedSteps {
        self {
            variable count
            method Count {} {
                return [incr count]
            }
        }
        method advanceTwice {} {
            puts "in [self] step A: [myclass Count]"
            puts "in [self] step B: [myclass Count]"
        }
    }

    CountedSteps create x
    CountedSteps create y
    x advanceTwice       → prints "in ::x step A: 1"
                         → prints "in ::x step B: 2"
    y advanceTwice       → prints "in ::y step A: 3"
                         → prints "in ::y step B: 4"
    x advanceTwice       → prints "in ::x step A: 5"
                         → prints "in ::x step B: 6"
    y advanceTwice       → prints "in ::y step A: 7"
                         → prints "in ::y step B: 8"

### SEE ALSO

next, oo::object, self

### KEYWORDS

method, method visibility, object, private method, public method
Copyright © 2007 Donal K. Fellows