Improve #to_str and #to_json for Version::NULL.

This commit is contained in:
Markus Reiter 2023-05-11 11:21:19 +02:00
parent fff93a8781
commit 5c9c089b68
No known key found for this signature in database
GPG Key ID: 245293B51702655B
2 changed files with 345 additions and 270 deletions

File diff suppressed because it is too large Load Diff

View File

@ -535,7 +535,7 @@ class Version
sig { returns(T::Boolean) }
def null?
@version.nil?
version.nil?
end
sig { params(comparator: String, other: Version).returns(T::Boolean) }
@ -703,7 +703,25 @@ class Version
def to_s
version.to_s
end
alias to_str to_s
sig { returns(String) }
def to_str
raise NoMethodError, "undefined method `to_str' for #{self.class}:NULL" if null?
T.must(version).to_str
end
sig { params(options: Hash).returns(String) }
def to_json(**options)
version.to_json(**options)
end
sig { params(method: T.any(Symbol, String), include_all: T::Boolean).returns(T::Boolean) }
def respond_to?(method, include_all = T.unsafe(nil))
return !null? if ["to_str", :to_str].include?(method)
super
end
sig { returns(String) }
def inspect