versionAt:

We implement the two visible methods in Contract – `#versionAt:put:` and `#versionAt:`. (In some cases you will want to make a Safe Copy of the Version before you store it, but we are just careful not to modify a Version after we have stored it in a History.)

Contract>>versionAt: aDate put: aVersion aVersion date: aDate. self versions add: aVersion

Contract>>versions "The instance variable “versions” will be lazily initialized to a SortedCollection of Versions. " versions isNil ifTrue: [versions := SortedCollection sortBlock: [:a :b | a date > b date]]. ^versions

I am still not quite clear what

> The instance variable “versions” will be lazily initialized to a SortedCollection of Versions.

means.

> A sort block takes two elements of the collection as parameter and should return a boolean describing if the first one should be before the second one. github

**Note**: 2 elements! ⇒ testPayToday: But in the context of this test case we are dealing with only 1 version. We change the `versionsAt:` method so that it detects with greater than or equal to (`>=`), instead of just greater than (`>`) – now we have implemented `Contract>>versionAt:` commit :

versionAt: aDate ^ self versions detect: [:each | aDate >= each date]

But the paper says:

Contract>>versionAt: aDate ^self versions detect: [:each | aPerspective > each date]