oo::copy − create copies of objects and classes


package require TclOO

oo::copy sourceObject ?targetObject? ___________________________


The oo::copy command creates a copy of an object or class. It takes the name of the object or class to be copied, sourceObject, and optionally the name of the object or class to create, targetObject, which will be resolved relative to the current namespace if not an absolute qualified name. If targetObject is omitted, a new name is chosen. The copied object will be of the same class as the source object, and will have all its per-object methods copied. If it is a class, it will also have all the class methods in the class copied, but it will not have any of its instances copied.

After the targetObject has been created and all definitions of its │ configuration (e.g., methods, filters, mixins) copied, the <cloned> │ method of targetObject will be invoked, to allow for customization of │ the created object such as installing related variable traces. The only │ argument given will be sourceObject. The default implementation of this │ method (in oo::object) just copies the procedures and variables in the │ namespace of sourceObject to the namespace of targetObject. If this │ method call does not return a result that is successful (i.e., an error │ or other kind of exception) then the targetObject will be deleted and │ an error returned.

The result of the oo::copy command will be the fully-qualified name of the new object or class.


This example creates an object, copies it, modifies the source object, and then demonstrates that the copied object is indeed a copy.

oo::object create src
oo::objdefine src method msg {} {puts foo}
src dst
oo::objdefine src method msg {} {puts bar}
src msg → prints "bar"
dst msg → prints "foo"


oo::class(n), oo::define(n), oo::object(n)


clone, copy, duplication, object

More Linux Commands

audit_encode_nv_string(3) - encode a name/value pair in a st
This function is used to encode a name/value pair. This should be used on any field being logged that potentially contains a space, a double-quote, or a control

gnutls_anon_free_client_credentials(3) - API function.......
gnutls_anon_free_client_credentials.3 - This structure is complex enough to manipulate directly thus this helper function is provided in order to free (dealloca

sysctl(2) - read/write system parameters - Linux man page...
Do not use this system call! See NOTES. The _sysctl() call reads and/or writes kernel parameters. For example, the hostname, or the maximum number of open files

gcjh(1) - - generate header files from Java class files.....
The gcjh program is used to generate header files from class files. It can generate both CNI and JNI header files, as well as stub implementation files which ca

hexdump(1) - display file contents in ascii, decimal, hexade
The hexdump utility is a filter which displays the specified files, or standard input if no files are specified, in a user-specified format. OPTIONS Below, the

ldap_objectclass2name(3) - Schema definition handling routin
These routines are used to parse schema definitions in the syntax defined in RFC 4512 into structs and handle these structs. These routines handle four kinds of

XpGetImageResolution(3x) - Gets the current image resolution
XpGetImageResolution returns the current image resolution for the specified print context. A value of zero means the resolution automatically tracks the printer

colrm(1) - remove columns from a file - Linux manual page...
colrm removes selected columns from a file. Input is taken from standard input. Output is sent to standard output. If called with one parameter the columns of e

vgcfgrestore(8) - restore volume group descriptor area......
vgcfgrestore allows you to restore the metadata of VolumeGroupName from a text backup file produced by vgcfgbackup. You can specify a backup file with --file. I

su(1) - run a shell with substitute user and group IDs......
su allows to run commands with a substitute user and group ID. When called without arguments, su defaults to running an interactive shell as root. For backward

hdestroy(3) - hash table management - Linux manual page.....
The three functions hcreate(), hsearch(), and hdestroy() allow the caller to create and manage a hash search table containing entries consisting of a key (a str

keyctl_instantiate_iov(3) - Instantiate a key from segmented
keyctl_assume_authority() assumes the authority for the calling thread to deal with and instantiate the specified uninstantiated key. The calling thread must ha

We can't live, work or learn in freedom unless the software we use is free.