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

The Version class processes string versions into comparable values

Methods

Included Modules

Comparable

External Aliases

== -> eql?

Attributes

ints  [R] 
version  [R] 

Public Class methods

Checks if version string is valid format

str:[String] the version string
return:[Boolean] true if the string format is correct, otherwise false

[Source]

    # File lib/rubygems/version.rb, line 25
25:   def self.correct?(version)
26:     case version
27:     when Integer, /\A\s*(\d+(\.\d+)*)*\s*\z/ then true
28:     else false
29:     end
30:   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 40
40:   def self.create(input)
41:     if input.respond_to? :version then
42:       input
43:     elsif input.nil? then
44:       nil
45:     else
46:       new input
47:     end
48:   end

Constructs a version from the supplied string

version:[String] The version string. Format is digit.digit…

[Source]

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

Public Instance methods

Compares two versions

other:[Version or .ints] other version to compare to
return:[Fixnum] -1, 0, 1

[Source]

     # File lib/rubygems/version.rb, line 125
125:   def <=>(other)
126:     return 1 unless other
127:     @ints <=> other.ints
128:   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 138
138:   def bump
139:     ints = build_array_from_version_string
140:     ints.pop if ints.size > 1
141:     ints[-1] += 1
142:     self.class.new(ints.join("."))
143:   end

Dump only the raw version string, not the complete object

[Source]

    # File lib/rubygems/version.rb, line 67
67:   def marshal_dump
68:     [@version]
69:   end

Load custom marshal format

[Source]

    # File lib/rubygems/version.rb, line 72
72:   def marshal_load(array)
73:     self.version = array[0]
74:   end

Strip ignored trailing zeros.

[Source]

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

Convert version to integer array

return:[Array] list of integers

[Source]

     # File lib/rubygems/version.rb, line 101
101:   def to_ints
102:     normalize unless @ints
103:     @ints
104:   end

Returns the text representation of the version

return:[String] version as string

[Source]

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

[Source]

     # File lib/rubygems/version.rb, line 106
106:   def to_yaml_properties
107:     ['@version']
108:   end

[Source]

     # File lib/rubygems/version.rb, line 110
110:   def version=(version)
111:     @version = version.to_s.strip
112:     normalize
113:   end

[Source]

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

[Validate]