Skip to content

Instantly share code, notes, and snippets.

@aalin
Created October 31, 2011 13:46
Show Gist options
  • Select an option

  • Save aalin/1327527 to your computer and use it in GitHub Desktop.

Select an option

Save aalin/1327527 to your computer and use it in GitHub Desktop.
class CaseComparator
def initialize(object, operator)
@object = object
@operator = operator
end
def ===(other)
other.send(@operator, @object)
end
end
class Object
def cc(operator)
CaseComparator.new(self, operator)
end
end
loop do
print "Enter a number: "
case gets.strip.to_i
when 5.cc(:>)
puts "More than 5!"
when 3.cc(:>)
puts "More than 3!"
else
puts "Less :("
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment