decorate: Sugar function for decoration

Description Usage Arguments See Also Examples

View source: R/sugar.R

Description

Simple wrapper around decorator$new(object, exists)

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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"))

ooplah documentation built on Jan. 21, 2022, 5:07 p.m.