Skip to content

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)

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

View source

.parse(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.

View source

Methods

#<=>(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
View source

#==(other : self)

#build : String?

The build metadata of this semantic version

View source

#hash(hasher)

#major : Int32

The major version of this semantic version

View source

#minor : Int32

The minor version of this semantic version

View source

#patch : Int32

The patch version of this semantic version

View source

#prerelease : Prerelease

The pre-release version of this semantic version

View source

#to_s(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"
View source