S3 method of addition operator of a
bandicoot_oop
object
Source: R/oop_s3.R
grapes-plus-grapes-.bandicoot_oop.Rd
This function performs the addition operator using the
..add..()
method.
If it is not applicable, error will be raised.
Examples
COMPANY <- new_class(class_name = "COMPANY")
company <- COMPANY$instantiate
register_method(COMPANY,
..init.. = function(name, age) {
self$name <- name
self$age <- age
})
register_method(COMPANY,
..add.. = function(y) {
company(c(self$name, y$name),
c(self$age, y$age))
})
good_company <- company(c("patrick", "james"),
c(33, 34))
bad_company <- company(c("pat", "jam"),
c(3, 4))
new_company <- good_company %+% bad_company
new_company$name
#> [1] "patrick" "james" "pat" "jam"