link(3tcl)

πŸ“¦
version 9.0.4 Β· 4 versions
, in ubuntu stonking

okay bestie, so this is link from the TclOO manual (section 3tcl, the commands section, iykyk) 🫢


✨ NAME ✨

link β€” create link from command to method of object πŸŽ€


🌸 SYNOPSIS 🌸

package require tcl::oo

link methodName ?...?
link {commandName methodName} ?...?

πŸ’… DESCRIPTION πŸ’…

So, the link command is available within methods β€” that's its whole vibe. It takes a series of one or more method names (methodName ...) and/or pairs of command- and method-name ({commandName methodName}), and it makes those named methods available as commands without you having to explicitly use the name of the object or the my command. Iconic, right? πŸ’…

lowkey the best part: the method does not need to exist at the time that the link is made. If the link command is invoked when the method does not exist, the standard unknown method handling system is used. no cap.

The command name under which the method becomes available defaults to the method name, except where explicitly specified through an alias/method pair. Formally (and yes, we're being formal now, sorry 😭): every argument must be a list. If the list has two elements, the first element is the name of the command to create and the second element is the name of the method of the current object to which the command links. Otherwise, the name of the command and the name of the method are the same string β€” that's the first element of the list.

And if the name of the command is not a fully-qualified command name, it will be resolved with respect to the current namespace (i.e., the object namespace). ✨


πŸ¦‹ EXAMPLES πŸ¦‹

This one demonstrates linking a single method in various ways. First it makes a simple link, then a renamed link, then an external link. Note that the method itself is unexported, but that it can still be called directly from outside the class. πŸ‘‘

oo::class create ABC {
    method Foo {} {
        puts "This is Foo in [self]"
    }

    constructor {} {
        link Foo
        # The method Foo is now directly accessible as Foo here
        link {bar Foo}
        # The method Foo is now directly accessible as bar
        link {::ExternalCall Foo}
        # The method Foo is now directly accessible in the global
        # namespace as ExternalCall
    }

    method grill {} {
        puts "Step 1:"
        Foo
        puts "Step 2:"
        bar
    }
}

ABC create abc
abc grill
        β†’ Step 1:
        β†’ This is Foo in ::abc
        β†’ Step 2:
        β†’ This is Foo in ::abc
# Direct access via the linked command
puts "Step 3:"; ExternalCall
        β†’ Step 3:
        β†’ This is Foo in ::abc

This next example shows that multiple linked commands can be made in a call to link, and that they can handle arguments. 🧚

oo::class create Ex {
    constructor {} {
        link a b c
        # The methods a, b, and c (defined below) are all now
        # directly accessible within methods under their own names.
    }

    method a {} {
        puts "This is a"
    }
    method b {x} {
        puts "This is b($x)"
    }
    method c {y z} {
        puts "This is c($y,$z)"
    }

    method call {p q r} {
        a
        b $p
        c $q $r
    }
}

set o [Ex new]
$o call 3 5 7
        β†’ This is a
        β†’ This is b(3)
        β†’ This is c(5,7)

🌈 SEE ALSO 🌈


⭐ KEYWORDS ⭐

command, method, object


and that's the whole page, bestie!! πŸ’œ no notes, we ate. this little beauty comes to you from TclOO, version 0.3, and it's the link(3tcl) page β€” main character energy only, periodt. πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from