Created
October 31, 2011 13:46
-
-
Save aalin/1327527 to your computer and use it in GitHub Desktop.
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
| 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