From d7553015cc63258919f28b41c642eca66d35f8bf Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 29 Jan 2026 20:39:23 +0100 Subject: [ruby/prism] Handle String-like objects for Ripper.sexp * RSpec relies on this in https://github.com/rspec/rspec/blob/rspec-support-v3.13.6/rspec-support/lib/rspec/support/source.rb#L57 which is given an RSpec::Support::EncodedString. * CI failure caused by this on truffleruby: https://github.com/sporkmonger/addressable/actions/runs/21457707372/job/61802608154#step:7:14 https://github.com/ruby/prism/commit/a83cb7b350 --- lib/prism/translation/ripper.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index 054ad88ce3..5b2aa37833 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -480,7 +480,17 @@ module Prism # Create a new Translation::Ripper object with the given source. def initialize(source, filename = "(ripper)", lineno = 1) - @source = source + if source.is_a?(IO) + @source = source.read + elsif source.respond_to?(:gets) + @source = +"" + while line = source.gets + @source << line + end + else + @source = source.to_str + end + @filename = filename @lineno = lineno @column = 0 -- cgit v1.2.3