Created
November 19, 2010 17:52
-
-
Save srawlins/706859 to your computer and use it in GitHub Desktop.
rbx: Bignum#<=> doesn't do something right... coersion?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In ruby-1.8.7 | |
C:\sam>irb | |
irb(main):001:0> class A | |
irb(main):002:1> @a | |
irb(main):003:1> def initialize(a) | |
irb(main):004:2> @a=a | |
irb(main):005:2> end | |
irb(main):006:1> def coerce(other) | |
irb(main):007:2> if other.is_a? Integer | |
irb(main):008:3> [A.new(other), self] | |
irb(main):009:3> else | |
irb(main):010:3* nil | |
irb(main):011:3> end | |
irb(main):012:2> end | |
irb(main):013:1> def <=>(other) | |
irb(main):014:2> @a <=> other.to_i | |
irb(main):015:2> end | |
irb(main):016:1> def to_i | |
irb(main):017:2> @a.to_i | |
irb(main):018:2> end | |
irb(main):019:1> end | |
=> nil | |
irb(main):020:0> five = A.new(5) | |
=> #<A:0x134a220 @a=5> | |
irb(main):021:0> (2**64) <=> five | |
=> 1 | |
In rbx-1.1.0 (or HEAD as of Nov 17, 2010), the last line returns nil instead. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment