[VW7.4][Bug] Fraction not read correctly from string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[VW7.4][Bug] Fraction not read correctly from string

Andre Schnoor
This expression fails to deliver the expected result:

    Fraction readFromString: '7/8'   => 7

The method Fraction>>readFrom: below fixes this:

readFrom: aStream
    "Answer an instance of me as described on the stream, aStream."
    | nom denom |
    (aStream atEnd or: [aStream peek isLetter])
        ifTrue:[ ^0 ].
    nom := super readFrom: aStream.
    (aStream peekFor: $/)
        ifTrue:[ denom := super readFrom: aStream ]
        ifFalse:[ denom := 1 ].
    ^nom / denom



Cheers,
Andre