From fa09afb15c9cf901d84e2963b86c4c7a7d0e104e Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 28 Jan 2026 21:23:15 -0500 Subject: [ruby/prism] Support `version: "nearest"`. This clamps to supported versions based on the current Ruby version. https://github.com/ruby/prism/commit/eb63748e8b --- lib/prism/ffi.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib') 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}" -- cgit v1.2.3