Class Gem::Version
In: lib/rubygems/version.rb
Parent: Object

The Version class processes string versions into comparable values

Methods

Included Modules

Comparable

Attributes

ints  [R] 
version  [R] 

Public Class methods

Returns true if version is a valid version string.

[Source]

    # File lib/rubygems/version.rb, line 23
23:   def self.correct?(version)
24:     case version
25:     when Integer, /\A\s*(\d+(\.\d+)*)*\s*\z/ then true
26:     else false
27:     end
28:   end

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

[Source]

    # File lib/rubygems/version.rb, line 38
38:   def self.create(input)
39:     if input.respond_to? :version then
40:       input
41:     elsif input.nil? then
42:       nil
43:     else
44:       new input
45:     end
46:   end

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

[Source]

    # File lib/rubygems/version.rb, line 52
52:   def initialize(version)
53:     raise ArgumentError, "Malformed version number string #{version}" unless
54:       self.class.correct?(version)
55: 
56:     self.version = version
57:   end

Public Instance methods

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

[Source]

     # File lib/rubygems/version.rb, line 120
120:   def <=>(other)
121:     return nil unless self.class === other
122:     return 1 unless other
123:     @ints <=> other.ints
124:   end

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

[Source]

     # File lib/rubygems/version.rb, line 140
140:   def bump
141:     ints = build_array_from_version_string
142:     ints.pop if ints.size > 1
143:     ints[-1] += 1
144:     self.class.new(ints.join("."))
145:   end

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

[Source]

     # File lib/rubygems/version.rb, line 130
130:   def eql?(other)
131:     self.class === other and @version == other.version
132:   end

Dump only the raw version string, not the complete object

[Source]

    # File lib/rubygems/version.rb, line 64
64:   def marshal_dump
65:     [@version]
66:   end

Load custom marshal format

[Source]

    # File lib/rubygems/version.rb, line 69
69:   def marshal_load(array)
70:     self.version = array[0]
71:   end

Strip ignored trailing zeros.

[Source]

    # File lib/rubygems/version.rb, line 76
76:   def normalize
77:     @ints = build_array_from_version_string
78: 
79:     return if @ints.length == 1
80: 
81:     @ints.pop while @ints.last == 0
82: 
83:     @ints = [0] if @ints.empty?
84:   end

Returns an integer array representation of this Version.

[Source]

     # File lib/rubygems/version.rb, line 98
 98:   def to_ints
 99:     normalize unless @ints
100:     @ints
101:   end

Returns the text representation of the version

return:[String] version as string

[Source]

    # File lib/rubygems/version.rb, line 91
91:   def to_s
92:     @version
93:   end

[Source]

     # File lib/rubygems/version.rb, line 103
103:   def to_yaml_properties
104:     ['@version']
105:   end

[Source]

     # File lib/rubygems/version.rb, line 107
107:   def version=(version)
108:     @version = version.to_s.strip
109:     normalize
110:   end

[Source]

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

[Validate]