class method
Gem::Version.new
(::_ToS version) -> ::Gem::Version
new(version)
lib/rubygems/version.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/rubygems/version.rb, line 206
def initialize(version)
unless self.class.correct?(version)
raise ArgumentError, "Malformed version number string #{version}"
end
# If version is an empty string convert it to 0
version = 0 if version.nil? || (version.is_a?(String) && /\A\s*\Z/.match?(version))
@version = version.to_s
# optimization to avoid allocation when given an integer, since we know
# it's to_s won't have any spaces or dashes
unless version.is_a?(Integer)
@version = @version.strip
@version.gsub!("-",".pre.")
end
@version = -@version
@segments = nil
end
Constructs a Version from the version string. A version string is a series of digits or ASCII letters separated by dots.