summaryrefslogtreecommitdiffstats
path: root/src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:07:37 +0000
commitb485aab7e71c1625cfc27e0f92c9509f42378458 (patch)
treeae9abe108601079d1679194de237c9a435ae5b55 /src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-b485aab7e71c1625cfc27e0f92c9509f42378458.tar.xz
netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.zip
Adding upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb')
-rw-r--r--src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb b/src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb
new file mode 100644
index 000000000..84b962598
--- /dev/null
+++ b/src/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb
@@ -0,0 +1,84 @@
+##
+# Comparable
+#
+# ISO 15.3.3
+module Comparable
+
+ ##
+ # Return true if +self+ is less
+ # than +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.1
+ def < other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp < 0
+ end
+
+ ##
+ # Return true if +self+ is less
+ # than or equal to +other+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.2
+ def <= other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp <= 0
+ end
+
+ ##
+ # Return true if +self+ is equal
+ # to +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.3
+ def == other
+ cmp = self <=> other
+ cmp == 0
+ end
+
+ ##
+ # Return true if +self+ is greater
+ # than +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.4
+ def > other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp > 0
+ end
+
+ ##
+ # Return true if +self+ is greater
+ # than or equal to +other+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.5
+ def >= other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp >= 0
+ end
+
+ ##
+ # Return true if +self+ is greater
+ # than or equal to +min+ and
+ # less than or equal to +max+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.6
+ def between?(min, max)
+ self >= min and self <= max
+ end
+end