Tag Archives: snipped

Snippet: Range#compare

Here’s a little idea that popped into my head for enhancing the Range class in Ruby: 1 2 3 4 5 6 7 8 9 10 11 class Range def compare( value ) if member?( value ) 0 elsif value <= self.begin -1 elsif value >= self.end 1 end end end Then you can perform [...]

Posted in Ruby, Snippets | Also tagged , , | Leave a comment