Class: Net::SSH::Version
- Inherits:
-
Object
- Object
- Net::SSH::Version
- Includes:
- Comparable
- Defined in:
- lib/net/ssh/version.rb
Overview
A class for describing the current version of a library. The version consists of three parts: the major
number, the minor
number, and the tiny
(or patch
) number.
Two Version instances may be compared, so that you can test that a version of a library is what you require:
require 'net/ssh/version'
if Net::SSH::Version::CURRENT < Net::SSH::Version[2,1,0]
abort "your software is too old!"
end
Constant Summary collapse
- MAJOR =
The major component of this version of the Net::SSH library
2
- MINOR =
The minor component of this version of the Net::SSH library
0
- TINY =
The tiny component of this version of the Net::SSH library
14
- CURRENT =
The current version of the Net::SSH library as a Version instance
new(MAJOR, MINOR, TINY)
- STRING =
The current version of the Net::SSH library as a String
CURRENT.to_s
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#tiny ⇒ Object
readonly
Returns the value of attribute tiny.
Class Method Summary collapse
-
.[](major, minor, tiny) ⇒ Object
A convenience method for instantiating a new Version instance with the given
major
,minor
, andtiny
components.
Instance Method Summary collapse
-
#<=>(version) ⇒ Object
Compare this version to the given
version
object. -
#initialize(major, minor, tiny) ⇒ Version
constructor
Create a new Version object with the given components.
-
#to_i ⇒ Object
Converts this version to a canonical integer that may be compared against other version objects.
-
#to_s ⇒ Object
Converts this version object to a string, where each of the three version components are joined by the ‘.’ character.
Constructor Details
#initialize(major, minor, tiny) ⇒ Version
Create a new Version object with the given components.
26 27 28 |
# File 'lib/net/ssh/version.rb', line 26 def initialize(major, minor, tiny) @major, @minor, @tiny = major, minor, tiny end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
23 24 25 |
# File 'lib/net/ssh/version.rb', line 23 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
23 24 25 |
# File 'lib/net/ssh/version.rb', line 23 def minor @minor end |
#tiny ⇒ Object (readonly)
Returns the value of attribute tiny.
23 24 25 |
# File 'lib/net/ssh/version.rb', line 23 def tiny @tiny end |
Class Method Details
.[](major, minor, tiny) ⇒ Object
A convenience method for instantiating a new Version instance with the given major
, minor
, and tiny
components.
19 20 21 |
# File 'lib/net/ssh/version.rb', line 19 def self.[](major, minor, tiny) new(major, minor, tiny) end |
Instance Method Details
#<=>(version) ⇒ Object
Compare this version to the given version
object.
31 32 33 |
# File 'lib/net/ssh/version.rb', line 31 def <=>(version) to_i <=> version.to_i end |
#to_i ⇒ Object
Converts this version to a canonical integer that may be compared against other version objects.
43 44 45 |
# File 'lib/net/ssh/version.rb', line 43 def to_i @to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny end |
#to_s ⇒ Object
Converts this version object to a string, where each of the three version components are joined by the ‘.’ character. E.g., 2.0.0.
37 38 39 |
# File 'lib/net/ssh/version.rb', line 37 def to_s @to_s ||= [@major, @minor, @tiny].join(".") end |