Skip to content

Instantly share code, notes, and snippets.

@darioappsilon
Created May 12, 2022 07:51
Show Gist options
  • Save darioappsilon/b801cfe01fc103b08f4205e363b753b6 to your computer and use it in GitHub Desktop.
Save darioappsilon/b801cfe01fc103b08f4205e363b753b6 to your computer and use it in GitHub Desktop.
Dog <- R6Class(
classname = "Dog",
public = list(
initialize = function(name = NA, age = NA, hair_color = NA) {
private$name = name
private$age = age
private$hair_color = hair_color
self$bark()
},
bark = function() {
cat(private$name, " says Woof!", sep = "")
},
show = function() {
cat("Dog: \n")
cat("\tName: ", private$name, "\n", sep = "")
cat("\tAge: ", private$age, " or ", private$dog_age(), " in dog years\n", sep = "")
cat("\tHair color: ", private$hair_color, "\n", sep = "")
}
),
private = list(
name = NULL,
age = NULL,
hair_color = NULL,
dog_age = function() {
return(private$age * 7)
}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment