SemanticVersion
Inherits Comparable / Struct / Value / Object
Conforms to Semantic Versioning 2.0.0
See https://semver.org/ for more information.
Constants
Constructors
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
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.
Class methods
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, ... >
Returns nil if str is not a semantic version.
Instance methods
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
Returns a copy of the current version with a major bump.
require "semantic_version"
current_version = SemanticVersion.new 1, 1, 1, "rc"
current_version.bump_major # => SemanticVersion(@build=nil, @major=2, @minor=0, @patch=0, @prerelease=SemanticVersion::Prerelease(@identifiers=[]))
Returns a copy of the current version with a minor bump.
require "semantic_version"
current_version = SemanticVersion.new 1, 1, 1, "rc"
current_version.bump_minor # => SemanticVersion(@build=nil, @major=1, @minor=2, @patch=0, @prerelease=SemanticVersion::Prerelease(@identifiers=[]))
Returns a copy of the current version with a patch bump. Bumping a patch of a prerelease just erase the prerelease data.
require "semantic_version"
current_version = SemanticVersion.new 1, 1, 1, "rc"
next_patch = current_version.bump_patch # => SemanticVersion(@build=nil, @major=1, @minor=1, @patch=1, @prerelease=SemanticVersion::Prerelease(@identifiers=[]))
next_patch.bump_patch # => SemanticVersion(@build=nil, @major=1, @minor=1, @patch=2, @prerelease=SemanticVersion::Prerelease(@identifiers=[]))
Returns a new SemanticVersion created with the specified parts. The
default for each part is its current value.
require "semantic_version"
current_version = SemanticVersion.new 1, 1, 1, "rc"
current_version.copy_with(patch: 2) # => SemanticVersion(@build=nil, @major=1, @minor=1, @patch=2, @prerelease=SemanticVersion::Prerelease(@identifiers=["rc"]))
current_version.copy_with(prerelease: nil) # => SemanticVersion(@build=nil, @major=1, @minor=1, @patch=1, @prerelease=SemanticVersion::Prerelease(@identifiers=[]))
See Object#hash(hasher)