This function copy attributes and methods from classes or instances to class or instance.
Usage
copy_attr(
env,
...,
avoid = c("..method_env..", "..init_call.."),
class_name = env$..type..
)
Arguments
- env
Environment. The destination environment.
- ...
Environments. Source environments.
- avoid
Character. Names that don't want to be copied.
- class_name
Character. Name of the class the method is defined. This is important for
super()
to resolve the correct parent class.
Details
Multiple classes or instances can be provided in ...
, where the right one
will override the left one if they have the same attribute or method name.
Attributes or methods that don't want to be copied can be specified in
avoid
.
Examples
test <- new.env()
names(BASE)
#> [1] "..mro.." "..str.." "..len.." "..class.."
#> [5] "..new.." "..repr.." "del_attr" "has_attr"
#> [9] "set_attr" "get_attr" "..type.." "..dir.."
#> [13] "..methods.." "..method_env.." "..init.." "..instantiated.."
#> [17] "..class_tree.." "instantiate"
copy_attr(test, BASE, avoid = c("..method_env..", "..init_call..", "..dir.."))
names(test)
#> [1] "..mro.." "..str.." "..len.." "..class.."
#> [5] "..new.." "has_attr" "del_attr" "..repr.."
#> [9] "set_attr" "..type.." "get_attr" "..methods.."
#> [13] "..method_env.." "..instantiated.." "..init.." "..class_tree.."
#> [17] "instantiate"