Created
January 15, 2011 23:19
-
-
Save apeiros/781361 to your computer and use it in GitHub Desktop.
A generic smaller/bigger implementation, for things like infinite ranges etc.
This file contains hidden or 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
(1..Bigger).first(5) # => [1, 2, 3, 4, 5] |
This file contains hidden or 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
Bigger = Object.new | |
Bigger.extend Comparable | |
def Bigger.inspect; "#<Bigger>"; end | |
def Bigger.<=>(other); equal?(other) ? 0 : 1; end | |
def Bigger.coerce(other); [Smaller, self]; end | |
Smaller = Object.new | |
Smaller.extend Comparable | |
def Smaller.inspect; "#<Smaller>"; end | |
def Smaller.<=>(other); equal?(other) ? 0 : -1; end | |
def Smaller.coerce(other); [Bigger, self]; end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment