On Tue, Sep 27, 2011 at 1:37 PM, Larry White <
ljw1001@gmail.com> wrote:
> Hi, I had a need to replace the printOn: implementation in ScaledDecimal so
> that it didn't include the scale. �In other words, I don't want my users to
> see '3.02s2'. �Being lazy, my first impulse was to remove the code from
> printOn: that appends the scale, but I realized I'd have to do that every
> time I upgraded my pharo version.
> Instead I tried to implement a subclass called DisplayableScaledDecimal and
> override printOn. �That seems straightforward and smalltalky, but when I do
> math on instances of DisplayableScaledDecimal, the results are converted
> back to ScaledDecimal. �Now I'm looking at re-implementing all the math
> logic in scaledDecimal to avoid that.
> The problem seems to be in the coerce: method, which reads:
> coerce: aNumber
> "Note: this quick hack could be replaced by double dispatching"
> aNumber class = self class ifTrue: [^self class newFromNumber: aNumber
> scale: (scale max: aNumber scale)].
> (aNumber isFraction or: [aNumber isInteger]) ifTrue: [^self class
> newFromNumber: aNumber scale: scale].
> ^aNumber
> I guess I could override coerce:, but that seems wrong.
> So my question to the smalltalk gods on the list is: Could this be fixed
> with double dispatching as the comment sort of suggests, and would it be a
> useful thing to do?