Skip to content

Instantly share code, notes, and snippets.

@nelsnelson
Created April 6, 2011 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsnelson/905896 to your computer and use it in GitHub Desktop.
Save nelsnelson/905896 to your computer and use it in GitHub Desktop.
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