Files
mruby-mruby/mrblib/compar.rb
T
Yukihiro "Matz" Matsumoto 07b803e28a docs: replace xml-style markup with markdown in comments
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)

Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:49 +09:00

103 lines
1.9 KiB
Ruby

##
# Comparable
#
# ISO 15.3.3
module Comparable
##
# call-seq:
# obj < other -> true or false
#
# 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
##
# call-seq:
# obj <= other -> true or false
#
# 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
##
# call-seq:
# obj == other -> true or false
#
# Return true if `self` is equal
# to `other`. Otherwise return
# false.
#
# ISO 15.3.3.2.3
def == other
cmp = self <=> other
cmp.equal?(0)
end
##
# call-seq:
# obj > other -> true or false
#
# 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
##
# call-seq:
# obj >= other -> true or false
#
# 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
##
# call-seq:
# obj.between?(min,max) -> true or false
#
# 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