<div dir="ltr"><div>I recently read the book "Discovering Smalltalk". I know it's quite dated and it's based on Smalltalk/V instead of Smalltalk-80, but I still learned a lot from it.</div><div><br></div><div>I implement the Gatekeeper example described on pages 428-430 in Cuis. It demonstrates using the <font face="monospace">becomes:</font> method to track all messages sent to a given object. I got it working, but I had to make a small modification to the <font face="monospace">ProtoObject</font> instance method <font face="monospace">becomes:</font>. I'm wondering if my change would break other uses of this method.</div><div><br></div><div>I replaced the line</div><div><br></div><div><font face="monospace">selfMethod = otherObjectMethod ifFalse: [<br></font></div><div><br></div><div>with</div><div><br></div><div><font face="monospace">selfMethod ~= nil and:<br>                                  [otherObjectMethod ~= nil] and:<br>                                       [selfMethod ~= otherObjectMethod] :: ifTrue: [<br></font></div><div><br></div><div>Here's my working Gatekeeper code where I renamed that class to HistoryProxy.</div><div><br></div><div><font face="monospace">Object subclass: #HistoryProxy<br>    instanceVariableNames: 'history object'<br>    classVariableNames: ''<br>    poolDictionaries: ''<br>    category: 'Demo'<br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">"class method"</font></div><div><font face="monospace">on: anObject<br>    ^ self new on: anObject<br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">"instance method"</font></div><div><font face="monospace">on: anObject<br>    history := OrderedCollection new.<br>    object := anObject shallowCopy.<br>    anObject become: self<br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">"instance method"</font></div><font face="monospace"></font><div><font face="monospace">doesNotUnderstand: aMessage<br>    "Record the message and reroute it to the object."<br></font><div><span style="font-family:monospace">    history add: aMessage.</span><br></div><font face="monospace">    ^ aMessage sendTo: object.<br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">"instance method"</font></div><div><font face="monospace">restoreAndProvideHistory<br></font><font face="monospace">    | result |<br></font><span style="font-family:monospace">    "Extract information before mutating because it won't be available afterwards."</span><br style="font-family:monospace"><font face="monospace">    result := history.<br>    self become: object.<br>    ^ result.</font><br></div><div><br></div><div>Here's an example of using this:</div><div><br></div><div><font face="monospace">date := Date today.<br>HistoryProxy on: date.<br>date monthName print.<br>date dayOfWeekName print.<br>date year print.<br>history := date restoreAndProvideHistory.<br>history print "an OrderedCollection(monthName dayOfWeekName year)"</font><br></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div></div>