Parent

Namespace

Included Modules

Class Index [+]

Quicksearch

Gem::Version

The Version class processes string versions into comparable values. A version string should normally be a series of numbers separated by periods. Each part (digits separated by periods) is considered its own number, and these are used for sorting. So for instance, 3.10 sorts higher than 3.2 because ten is greater than two.

If any part contains letters (currently only a-z are supported) then that version is considered prerelease. Versions with a prerelease part in the Nth part sort less than versions with N-1 parts. Prerelease parts are sorted alphabetically using the normal Ruby string sorting rules.

Prereleases sort between real releases (newest to oldest):

  1. 1.0
  2. 1.0.b
  3. 1.0.a
  4. 0.9

Constants

VERSION_PATTERN
(Not documented)

Attributes

version[R]

(Not documented)

Public Class Methods

correct?(version) click to toggle source

(Not documented)

# File lib/rubygems/version.rb, line 76
  def self.correct?(version)
    pattern = /\A\s*(#{VERSION_PATTERN})*\s*\z/

    version.is_a? Integer or
      version =~ pattern or
      version.to_s =~ pattern
  end
create(input) click to toggle source

Factory method to create a Version object. Input may be a Version or a String. Intended to simplify client code.

  ver1 = Version.create('1.3.17')   # -> (Version object)
  ver2 = Version.create(ver1)       # -> (ver1)
  ver3 = Version.create(nil)        # -> nil
# File lib/rubygems/version.rb, line 92
  def self.create(input)
    if input.respond_to? :version then
      input
    elsif input.nil? then
      nil
    else
      new input
    end
  end
new(version) click to toggle source

Constructs a Version from the version string. A version string is a series of digits or ASCII letters separated by dots.

# File lib/rubygems/version.rb, line 106
  def initialize(version)
    raise ArgumentError, "Malformed version number string #{version}" unless
      self.class.correct?(version)

    self.version = version
  end

Public Instance Methods

<=>(other) click to toggle source

Compares this version with other returning -1, 0, or 1 if the other version is larger, the same, or smaller than this one.

# File lib/rubygems/version.rb, line 188
  def <=>(other)
    return nil unless self.class === other
    return 1 unless other
    mine, theirs = balance(self.parts.dup, other.parts.dup)
    mine <=> theirs
  end
balance(a, b) click to toggle source

(Not documented)

# File lib/rubygems/version.rb, line 195
  def balance(a, b)
    a << Part.new(0) while a.size < b.size
    b << Part.new(0) while b.size < a.size
    [a, b]
  end
bump() click to toggle source

Return a new version object where the next to the last revision number is one greater. (e.g. 5.3.1 => 5.4)

Pre-release (alpha) parts are ignored. (e.g 5.3.1.b2 => 5.4)

# File lib/rubygems/version.rb, line 219
  def bump
    parts = parse_parts_from_version_string
    parts.pop while parts.any? { |part| part.alpha? }
    parts.pop if parts.size > 1
    parts[-1] = parts[-1].succ
    self.class.new(parts.join("."))
  end
eql?(other) click to toggle source

A Version is only eql? to another version if it has the same version string. “1.0“ is not the same version as “1”.

# File lib/rubygems/version.rb, line 205
  def eql?(other)
    self.class === other and @version == other.version
  end
marshal_dump() click to toggle source

Dump only the raw version string, not the complete object

# File lib/rubygems/version.rb, line 120
  def marshal_dump
    [@version]
  end
marshal_load(array) click to toggle source

Load custom marshal format

# File lib/rubygems/version.rb, line 127
  def marshal_load(array)
    self.version = array[0]
  end
normalize() click to toggle source

Strip ignored trailing zeros.

# File lib/rubygems/version.rb, line 138
  def normalize
    parts_arr = parse_parts_from_version_string
    if parts_arr.length != 1
      parts_arr.pop while parts_arr.last && parts_arr.last.value == 0
      parts_arr = [Part.new(0)] if parts_arr.empty?
    end
    parts_arr
  end
parts() click to toggle source

(Not documented)

# File lib/rubygems/version.rb, line 131
  def parts
    @parts ||= normalize
  end
prerelease?() click to toggle source

A version is considered a prerelease if any part contains a letter.

# File lib/rubygems/version.rb, line 166
  def prerelease?
    parts.any? { |part| part.alpha? }
  end
release() click to toggle source

The release for this version (e.g. 1.2.0.a -> 1.2.0) Non-prerelease versions return themselves

# File lib/rubygems/version.rb, line 173
  def release
    return self unless prerelease?
    rel_parts = parts.dup
    rel_parts.pop while rel_parts.any? { |part| part.alpha? }
    self.class.new(rel_parts.join('.'))
  end
to_s() click to toggle source

Returns the text representation of the version

# File lib/rubygems/version.rb, line 150
  def to_s
    @version
  end
to_yaml_properties() click to toggle source

(Not documented)

# File lib/rubygems/version.rb, line 154
  def to_yaml_properties
    ['@version']
  end
version=(version) click to toggle source

(Not documented)

# File lib/rubygems/version.rb, line 158
  def version=(version)
    @version = version.to_s.strip
    normalize
  end
yaml_initialize(tag, values) click to toggle source

(Not documented)

# File lib/rubygems/version.rb, line 180
  def yaml_initialize(tag, values)
    self.version = values['version']
  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.