Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module TrueFalseComparison
- def <=>(other)
- return nil if ![TrueClass, FalseClass].include?(other.class)
- self.is_a?(FalseClass) ? (other.is_a?(TrueClass) ? -1 : 0) : (other.is_a?(FalseClass) ? 1 : 0)
- end
- end
- TrueClass.send(:include, TrueFalseComparison)
- FalseClass.send(:include, TrueFalseComparison)
- >> true <=> false
- => 1
- >> true <=> true
- => 0
- >> true <=> 'asdf'
- => nil
- >> false <=> false
- => 0
- >> false <=> true
- => -1
- >> false <=> 'asdf'
- => nil
- >> [1,2,3,4].sort_by { |n| n==3 }
- => [1, 2, 4, 3]
Add Comment
Please, Sign In to add comment