Skip to content

Commit bca02b1

Browse files
authored
Use Prism::Translation::ParserCurrent in prism docs (#1073)
This wasn't available when I wrote this.
1 parent 5810211 commit bca02b1

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

doc/PRISM_TRANSLATION.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,17 @@ RUBY
3232

3333
## Using `prism` when parsing ruby for the currently running Ruby version
3434

35-
If you are using `Parser::CurrentRuby`, you need to do similar branching logic. Do note that `prism` has no concept of a parser for the currently executing ruby version. As an alternative, you can manually extract the necessary version from the `RUBY_VERSION` constant:
35+
If you are using `Parser::CurrentRuby`, you need to do similar branching logic:
3636

3737
```rb
3838
def parser_for_current_ruby
39-
code_version = RUBY_VERSION.to_f
40-
41-
if code_version <= 3.3
39+
if Gem::Version.new(RUBY_VERSION) <= '3.3'
4240
require 'parser/current'
4341
Parser::CurrentRuby
4442
else
4543
require 'prism'
46-
case code_version
47-
when 3.3
48-
Prism::Translation::Parser33
49-
when 3.4
50-
Prism::Translation::Parser34
51-
else
52-
warn "Unknown Ruby version #{code_version}, using 3.4 as a fallback"
53-
Prism::Translation::Parser34
54-
end
44+
# Only available on prism > 1.4.0
45+
Prism::Translation::ParserCurrent
5546
end
5647
end
5748

0 commit comments

Comments
 (0)