Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of JRuby Fixnum problem.
#! /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