Created
December 7, 2017 08:04
-
-
Save EastResident/3767e08fd57fcb0b38d19909b381c784 to your computer and use it in GitHub Desktop.
1 < x < 10
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
{ '<' => [-1], '>' => [1], '<=' => [-1, 0], '>= ' => [1, 0]}.each do |ope, v| | |
[TrueClass, FalseClass].each do |klass| | |
klass.class_eval("def #{ope}(num); self ? value #{ope} num : false;end") | |
end | |
[Integer, Float].each do |klass| | |
klass.class_eval do | |
define_method(ope) do |n| | |
return false unless v.include? (self <=> n) | |
TrueClass.class_eval("def value; #{n};end") | |
true | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment