by __jonas · 1y ago · 0 comments
parts = version_string.to_s.split(”.”).map(&:to_i)
Is it to_string? Isn't version_string already a string? def bump_minor
self.class.new(major, minor + 1, patch)
end
(although I'm not sure why it would be useful in that particular case, it's just an example of how you can build new objects out of existing ones without having to mutate them)I think it's a safety measure in case the argument passed in is not a string, but can be turned into a string. Safe to assume that calling "to_s" on a string just returns the string.
It's also a quite bad practice to my eye.
if x.is_a? Array
x = x.first
Or something like that. Could be one line too: x = x.first if x.is_a? ArrayEven if you implement an "interface" (duck typing) with `respond_to?(:to_app_version)` you still can't be sure that the return type of this `:to_app_version` is actually a string you can call `split()` on.