Sha256: 3d528f87f294e30913be2edb929a9af17b7ba781499459010f6072a288d5e0a2

Contents?: true

Size: 1.53 KB

Versions: 38

Compression:

Stored size: 1.53 KB

Contents

##
# 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

Version data entries

38 entries across 38 versions & 3 rubygems

Version Path
script_core-0.3.2 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.3.0 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.7 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.6 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.5 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.4 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.3 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.2 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.1 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.2.0 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.1.1 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.1.0 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.0.6 ext/enterprise_script_service/mruby/mrblib/compar.rb
script_core-0.0.5 ext/enterprise_script_service/mruby/mrblib/compar.rb
esruby-0.2.0 resources/mruby/mrblib/compar.rb
esruby-0.1.5 resources/mruby/mrblib/compar.rb
esruby-0.1.4 resources/mruby/mrblib/compar.rb
esruby-0.1.3 resources/mruby/mrblib/compar.rb
esruby-0.1.2 resources/mruby/mrblib/compar.rb
esruby-0.1.1 resources/mruby/mrblib/compar.rb