Skip to content

Instantly share code, notes, and snippets.

@0x0dea
Created August 8, 2015 08:36
Show Gist options
  • Save 0x0dea/9eef255ce5bda81c67bb to your computer and use it in GitHub Desktop.
Save 0x0dea/9eef255ce5bda81c67bb to your computer and use it in GitHub Desktop.
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