Class: Version
Overview
This class stores numbers with multiple decimal points, a format commonly used for version numbers. For example ‘2.5.1’.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
12 13 14 |
# File 'lib/tpkg/versiontype.rb', line 12 def initialize(version) @version = version.to_s end |
Instance Method Details
#<=>(other) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tpkg/versiontype.rb', line 20 def <=>(other) ourfields = @version.split('.') otherfields = other.to_s.split('.') # Convert anything like '.5' to '0.5' # '.5'.split('.') returns ['', '5'] [ourfields, otherfields].each do |fields| if fields[0] == '' fields[0] = '0' end end convert_and_split!(ourfields, otherfields) # Array conveniently implements <=> ourfields <=> otherfields end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/tpkg/versiontype.rb', line 16 def to_s @version end |