Closed Fryguy closed 5 months ago
I do realize there is fuzzy matching involved here, but I feel like the algorithm is unexpectedly picking things. So, the algorithm picks the "last" one, but I wonder instead if it should pick the one where it matched most to the left of the string or something to that effect.
Story time - I think it's useful to know how this occurred for me.
Our application uses Ruby 3.0 at the moment, so in my .profile
I do chruby 3.0
, since that's the version I typically want in a new Terminal tab. I don't want to hardcode the full 3 digit version, because I generally update to the latest, and 3.0 "Just Works" as I install the latest patch versions.
Recently, I installed Ruby 3.3.0 to play with the new features. Existing Terminal tabs were fine, and I guess I didn't notice new tabs, however when my Terminal restarted all of the tabs were reopened but with Ruby 3.3.0. On top of that trying to switch back to 3.0 with chruby 3.0
didn't work! I thought I was stuck, but I was able to workaround it by doing chruby 3.0.6
.
Gah - just noticed this is a duplicate of https://github.com/postmodern/chruby/issues/291 . Didn't see that when i was searching.
Description
When 2 different rubies are installed where a shared substring is in both, chruby can pick the wrong one. For example, if I have ruby 3.0.6 and ruby 3.3.0 installed, and I say
chruby 3.0
, it will choose ruby 3.3.0, which is unexpected as I asked for the "3.0" series. I believe this is happening because the string "3.0" is actually present in both "3.0.6" and "3.3.0", and so the substring matches on both.Steps To Reproduce
Steps to reproduce the bug:
ruby-install ruby 3.0.6
andruby-install ruby 3.3.0
chruby 3.0
I can similarly demonstrate this with an example that makes it more evident that the behavior is unexpected
ruby-install ruby 3.0.6
chruby 0.6
My expectation there would be that chruby should fail to find anything because
0.6
is not a real version. You can also use similarly strange things likechruby .6
or evenchruby 6
and both of those resolve to3.0.6
, which is unexpectedExpected Behavior
Actual Behavior
Environment