A simple counter

Description

An R6 class, kept deliberately small. Exists to show another case reftip can’t resolve: a call through $, like counter$increment(), since nothing in the source says which class’s methods to look up (see reftip’s known limitations).

Methods

Public methods


Counter$new()

Create a new counter.

Usage
Counter\$new(start = 0)
Arguments
start
Numeric. The starting value.

Counter$increment()

Increment the counter.

Usage
Counter\$increment(by = 1)
Arguments
by
Numeric. The amount to increment by.

Counter$value()

Read the current value.

Usage
Counter\$value()

Counter$clone()

The objects of this class are cloneable with this method.

Usage
Counter\$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.

Examples

library("alttip")

counter <- Counter$new()
counter$increment()
counter$increment(by = 2)
counter$value()
[1] 3