decorate {ooplah}R Documentation

Sugar function for decoration

Description

Simple wrapper around decorator$new(object, exists)

Usage

decorate(object, decorators, exists = c("skip", "error", "overwrite"), ...)

Arguments

object

⁠[R6::R6Class]⁠
R6 class to decorate.

decorators

⁠([DecorateClass]|character())⁠
One or more decorators (by name or class) to decorate with.

exists

⁠(character(1)⁠
Expected behaviour if method exists in object and decorator. One of: 1. exists = "error" (default) - This will throw an error and prevent the object being decorated. 2. exists = "skip" - This will decorate the object with all fields/methods that don't already exist. 3. exists = "overwrite" - This will decorate the object with all fields/methods from the decorator and overwrite ones with the same name if they already exist.

...

ANY
Additional arguments passed to get.

See Also

DecoratorClass

Examples

library(R6)

## Define decorators
dec1 <- DecoratorClass("dec1", public = list(goodbye = "Goodbye World"))
dec2 <- DecoratorClass("dec2", public = list(goodbye2 = "Goodbye World 2"))

oop <- ooplah$new()
oop$goodbye
dec_oop <- decorate(oop, c(dec1, dec2))
dec_oop$goodbye
dec_oop$goodbye2

## Equivalently
oop <- ooplah$new()
decorate(oop, c("dec1", "dec2"))


[Package ooplah version 0.2.0 Index]