diff options
| author | Benoit Daloze <eregontp@gmail.com> | 2026-01-29 20:39:23 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-01-30 18:46:00 +0000 |
| commit | d7553015cc63258919f28b41c642eca66d35f8bf (patch) | |
| tree | c95d4d469fff235f3513e941cf520d138408930c /lib | |
| parent | 1298f9ac1ad390594815bc4d3739eb312bca8887 (diff) | |
[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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/prism/translation/ripper.rb | 12 |
1 files changed, 11 insertions, 1 deletions
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 |
