# NOT RUN {
# In module a:
print.my_class = function (x) {
cat(sprintf('My class with field %s\n', x$field))
invisible(x)
}
register_S3_method('print', 'my_class', print.my_class)
# Globally:
a = import('a')
obj = structure(list(field = 42), class = 'my_class')
obj # calls `print`, with output "My class with field 42"
# }
Run the code above in your browser using DataLab