[前][次][番号順一覧][スレッド一覧]

ruby-changes:70109

From: Yusuke <ko1@a...>
Date: Thu, 9 Dec 2021 00:30:34 +0900 (JST)
Subject: [ruby-changes:70109] 17e7219679 (master): ext/ripper/lib/ripper/lexer.rb: Do not deprecate Ripper::Lexer::State#[]

https://git.ruby-lang.org/ruby.git/commit/?id=17e7219679

From 17e7219679fc66cfc7a687c7fbae1bf2329beed5 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Mon, 6 Dec 2021 11:35:54 +0900
Subject: ext/ripper/lib/ripper/lexer.rb: Do not deprecate
 Ripper::Lexer::State#[]

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.

https://github.com/ruby/ruby/pull/5093
---
 ext/ripper/lib/ripper/lexer.rb | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index cc1f74f1e35..19c59e2cccf 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -64,12 +64,12 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L64
 
       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
 
@@ -97,21 +97,18 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L97
 
       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
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]