In Files

  • mrblib/compar.rb
  • mrblib/string.rb

Methods

Comparable

Comparable

ISO 15.3.3

String is comparable

ISO 15.2.10.3

Public Instance Methods

<(other) click to toggle source

Return true if self is less than other. Otherwise return false.

ISO 15.3.3.2.1

 
               # File mrblib/compar.rb, line 13
def < other
  cmp = self <=> other
  if cmp.nil?
    raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
  elsif cmp < 0
    true
  else
    false
  end
end
            
<=(other) click to toggle source

Return true if self is less than or equal to other. Otherwise return false.

ISO 15.3.3.2.2

 
               # File mrblib/compar.rb, line 30
def <= other
  cmp = self <=> other
  if cmp.nil?
    raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
  elsif cmp <= 0
    true
  else
    false
  end
end
            
==(other) click to toggle source

Return true if self is equal to other. Otherwise return false.

ISO 15.3.3.2.3

 
               # File mrblib/compar.rb, line 47
def == other
  cmp = self <=> other
  if cmp == 0
    true
  else
    false
  end
end
            
>(other) click to toggle source

Return true if self is greater than other. Otherwise return false.

ISO 15.3.3.2.4

 
               # File mrblib/compar.rb, line 62
def > other
  cmp = self <=> other
  if cmp.nil?
    raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
  elsif cmp > 0
    true
  else
    false
  end
end
            
>=(other) click to toggle source

Return true if self is greater than or equal to other. Otherwise return false.

ISO 15.3.3.2.5

 
               # File mrblib/compar.rb, line 79
def >= other
  cmp = self <=> other
  if cmp.nil?
    raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
  elsif cmp >= 0
    true
  else
    false
  end
end
            
between?(min, max) click to toggle source

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

 
               # File mrblib/compar.rb, line 97
def between?(min, max)
  if self < min or self > max
    false
  else
    true
  end
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus