Conforms to Semantic Versioning 2.0.0
See https://semver.org/ for more information.
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)
(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?
(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/x Creates a new SemanticVersion instance with the given major, minor, and patch versions and optionally build and pre-release version
Parses a SemanticVersion from the given semantic version string.
Parses a SemanticVersion from the given semantic version string.
Checks if str is a valid semantic version.
The comparison operator.
The build metadata of this semantic version
Returns a copy of the current version with a major bump.
Returns a copy of the current version with a minor bump.
Returns a copy of the current version with a patch bump.
Returns a new SemanticVersion created with the specified parts.
The major version of this semantic version
The minor version of this semantic version
The patch version of this semantic version
The pre-release version of this semantic version
Returns the string representation of this semantic version
Comparable(SemanticVersion)
Struct
Struct
Value
Object
Object
Object
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.
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.
Checks if str is a valid semantic version.
require "semantic_version"
SemanticVersion.valid?("1.15.0") # => true
SemanticVersion.valid?("1.2") # => false
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=[]))
The pre-release version of this semantic version
Returns the string representation of this semantic version
require "semantic_version"
semver = SemanticVersion.parse("0.27.1")
semver.to_s # => "0.27.1"
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/SemanticVersion.html