Skip to content

Instantly share code, notes, and snippets.

@EastResident
Created December 7, 2017 08:04
Show Gist options
  • Save EastResident/3767e08fd57fcb0b38d19909b381c784 to your computer and use it in GitHub Desktop.
Save EastResident/3767e08fd57fcb0b38d19909b381c784 to your computer and use it in GitHub Desktop.
1 < x < 10
{ '<' => [-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