-
-
Save 0x0dea/9eef255ce5bda81c67bb to your computer and use it in GitHub Desktop.
This file contains 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
module ChainedComparisons | |
refine Fixnum do | |
%i[< <= > >=].each do |op| | |
define_method(op) { |other| super @@n = other } | |
end | |
end | |
[TrueClass, FalseClass].each do |klass| | |
refine klass do | |
%i[< <= > >=].each do |op| | |
define_method(op) { |other| @@n.send op, other } | |
end | |
end | |
end | |
end | |
using ChainedComparisons | |
p 1 < 2 <= 3 | |
p 1 < 3 <= 2 | |
p 3 >= 2 > 1 | |
p 2 > 1 >= 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment