summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2026-01-28 21:23:15 -0500
committergit <svn-admin@ruby-lang.org>2026-01-29 02:35:38 +0000
commitfa09afb15c9cf901d84e2963b86c4c7a7d0e104e (patch)
treeb8446fdceae0f231520b5100e7c2a86d2e9b25d4 /lib
parent0c30897d0bf579ee7be08fc828932e1bac1196aa (diff)
[ruby/prism] Support `version: "nearest"`.
This clamps to supported versions based on the current Ruby version. https://github.com/ruby/prism/commit/eb63748e8b
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/ffi.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb
index d4c9d60c9a..57d878a33f 100644
--- a/lib/prism/ffi.rb
+++ b/lib/prism/ffi.rb
@@ -423,10 +423,26 @@ module Prism
# Return the value that should be dumped for the version option.
def dump_options_version(version)
- current = version == "current"
+ checking =
+ case version
+ when "current"
+ RUBY_VERSION
+ when "latest"
+ nil
+ when "nearest"
+ if RUBY_VERSION <= "3.3"
+ "3.3"
+ elsif RUBY_VERSION >= "4.1"
+ "4.1"
+ else
+ RUBY_VERSION
+ end
+ else
+ version
+ end
- case current ? RUBY_VERSION : version
- when nil, "latest"
+ case checking
+ when nil
0 # Handled in pm_parser_init
when /\A3\.3(\.\d+)?\z/
1
@@ -437,7 +453,7 @@ module Prism
when /\A4\.1(\.\d+)?\z/
4
else
- if current
+ if version == "current"
raise CurrentVersionError, RUBY_VERSION
else
raise ArgumentError, "invalid version: #{version}"