| Class | Gem::Version |
| In: |
lib/rubygems/version.rb
|
| Parent: | Object |
The Version class processes string versions into comparable values
| == | -> | eql? |
| ints | [R] | |
| version | [R] |
Checks if version string is valid format
| str: | [String] the version string |
| return: | [Boolean] true if the string format is correct, otherwise false |
# 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
# 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… |
# 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
Return a new version object where the next to the last revision number is one greater. (e.g. 5.3.1 => 5.4)
# 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
# File lib/rubygems/version.rb, line 67
67: def marshal_dump
68: [@version]
69: end
Load custom marshal format
# File lib/rubygems/version.rb, line 72
72: def marshal_load(array)
73: self.version = array[0]
74: end
Strip ignored trailing zeros.
# 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 |
# 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 |
# File lib/rubygems/version.rb, line 92
92: def to_s
93: @version
94: end
# File lib/rubygems/version.rb, line 110
110: def version=(version)
111: @version = version.to_s.strip
112: normalize
113: end