Is there a way to get the actual class name being used when calling a S3 method?
For example, is there a way to have foo.bar()
always print Call method for class: bar
independently of the order (and without knowing other class names) of the classes defined in structure()
?
foo <- function(x) {
UseMethod("foo")
}
foo.bar <- function(x) {
cat("Call method for class:", class(x)[[2]])
}
x <- structure("x", class = c("baz", "bar", "character"))
foo(x)