#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/History_variables
#

class HistoryVar(v) {

    has history = []
    has variable = v

    method ≔(value) {
        history << variable
        variable = value
    }

    method to_s {
        "#{variable}"
    }

    method AUTOLOAD(_, name, *args) {
        variable.(name)(args...)
    }
}

var foo = HistoryVar(0)

foo ≔ 1
foo ≔ 2
foo ≔ foo+3
foo ≔ 42

say "History: #{foo.history}"
say "Current value: #{foo}"

assert_eq(foo.history, [0,1,2,5])
assert_eq(foo.variable, 42)