Skip to content

Commit

Permalink
ext/ripper/lib/ripper/lexer.rb: Do not deprecate Ripper::Lexer::State#[]
Browse files Browse the repository at this point in the history
The old code of IRB still uses this method. The warning is noisy on
rails console.
In principle, Ruby 3.1 deprecates nothing, so let's avoid the
deprecation for the while.
I think It is not so hard to continue to maintain it as it is a trivial
shim.

#5093
  • Loading branch information
mame committed Dec 8, 2021
1 parent 3021c3c commit 17e7219
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions ext/ripper/lib/ripper/lexer.rb
Expand Up @@ -64,12 +64,12 @@ def initialize(i)

def [](index)
case index
when 0
warn "Calling `Lexer::State#[0]` is deprecated, please use `Lexer::State#to_int` instead"
when 0, :to_int
@to_int
when 1
warn "Calling `Lexer::State#[1]` is deprecated, please use `Lexer::State#to_s` instead"
when 1, :to_s
@event
else
nil
end
end

Expand Down Expand Up @@ -97,21 +97,18 @@ def initialize(pos, event, tok, state, message = nil)

def [](index)
case index
when 0
warn "Calling `Lexer::Elem#[0]` is deprecated, please use `Lexer::Elem#pos` instead"
when 0, :pos
@pos
when 1
warn "Calling `Lexer::Elem#[1]` is deprecated, please use `Lexer::Elem#event` instead"
when 1, :event
@event
when 2
warn "Calling `Lexer::Elem#[2]` is deprecated, please use `Lexer::Elem#tok` instead"
when 2, :tok
@tok
when 3
warn "Calling `Lexer::Elem#[3]` is deprecated, please use `Lexer::Elem#state` instead"
when 3, :state
@state
when 4
warn "Calling `Lexer::Elem#[4]` is deprecated, please use `Lexer::Elem#message` instead"
when 4, :message
@message
else
nil
end
end

Expand Down

0 comments on commit 17e7219

Please sign in to comment.