struct SemanticVersion
inherits Struct
¶
Conforms to Semantic Versioning 2.0.0
See https://semver.org/ for more information.
Included modules
Comparable
Class methods¶
.new(major : Int, minor : Int, patch : Int, prerelease : String | Prerelease | Nil = nil, build : String? = nil)
¶
(major : Int, minor : Int, patch : Int, prerelease : String | Prerelease | Nil = nil, build : String? = nil)
Creates a new SemanticVersion
instance with the given major, minor, and patch versions
and optionally build and pre-release version
Raises ArgumentError
if prerelease is invalid pre-release version
.parse(str : String) : self
¶
(str : String) : self
Parses a SemanticVersion
from the given semantic version string
require "semantic_version"
semver = SemanticVersion.parse("2.61.4")
semver # => #<SemanticVersion:0x55b3667c9e70 @major=2, @minor=61, @patch=4, ... >
Raises ArgumentError
if str is not a semantic version.
Methods¶
#<=>(other : self) : Int32
¶
(other : self) : Int32
The comparison operator.
Returns -1
, 0
or 1
depending on whether self
's version is lower than other's,
equal to other's version or greater than other's version.
require "semantic_version"
semver1 = SemanticVersion.new(1, 0, 0)
semver2 = SemanticVersion.new(2, 0, 0)
semver1 <=> semver2 # => -1
semver2 <=> semver2 # => 0
semver2 <=> semver1 # => 1
#==(other : self)
¶
(other : self)
#hash(hasher)
¶
(hasher)
#to_s(io : IO) : Nil
¶
(io : IO) : Nil
Returns the string representation of this semantic version
require "semantic_version"
semver = SemanticVersion.parse("0.27.1")
semver.to_s # => "0.27.1"