Created
April 6, 2011 15:48
-
-
Save nelsnelson/905896 to your computer and use it in GitHub Desktop.
Example of JRuby Fixnum problem.
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
#! /usr/bin/env ruby | |
class Fixnum | |
def < (other) | |
puts "Determining membership of #{self.inspect} in #{other.inspect}..." | |
return false unless other | |
if other.is_a? Enumerable or other.is_a? Array | |
other >= self | |
else | |
puts "The given other is not a list. Invoking super..." | |
super | |
end | |
end | |
end | |
class Array | |
def >= (other) | |
return false unless other | |
include? other | |
end | |
end | |
class Object | |
def in?(other) | |
return false unless other | |
return other.include?(self) if other.is_a? Enumerable or other.is_a? Array | |
false | |
end | |
end | |
puts "2.in? [ 1, 3, 5, 2, 7 ] # => #{2.in? [ 1, 3, 5, 2, 7 ]}" | |
puts "2 < [ 1, 3, 5, 2, 7 ] # => #{2 < [ 1, 3, 5, 2, 7 ]}" | |
puts "2 < 3 # => #{2 < 3}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment