ruby-changes:70013
From: schneems <ko1@a...>
Date: Thu, 2 Dec 2021 15:55:55 +0900 (JST)
Subject: [ruby-changes:70013] 8944009be7 (master): Deprecate `Lexer::Elem#[]` and `Lexer::State#[]`
https://git.ruby-lang.org/ruby.git/commit/?id=8944009be7 From 8944009be7418614ce7d4077807ac2b60d4d5d85 Mon Sep 17 00:00:00 2001 From: schneems <richard.schneeman+foo@g...> Date: Thu, 11 Nov 2021 08:59:29 -0600 Subject: Deprecate `Lexer::Elem#[]` and `Lexer::State#[]` Discussed in https://github.com/ruby/ruby/pull/5093#issuecomment-964426481. > it would be enough to mimic only [] for almost all cases This adds back the `Lexer::Elem#[]` and `Lexer::State#[]` and adds deprecation warnings for them. --- ext/ripper/lib/ripper/lexer.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb index a2d4d655b5b..23db3a05708 100644 --- a/ext/ripper/lib/ripper/lexer.rb +++ b/ext/ripper/lib/ripper/lexer.rb @@ -62,6 +62,17 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L62 freeze end + def [](index) + case index + when 0 + warn "Calling `Lexer::State#[0]` is deprecated, please use `Lexer::State#to_int` instead" + @to_int + when 1 + warn "Calling `Lexer::State#[1]` is deprecated, please use `Lexer::State#to_s` instead" + @event + end + end + alias to_i to_int alias inspect to_s def pretty_print(q) q.text(to_s) end @@ -84,6 +95,26 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L95 @message = message end + def [](index) + case index + when 0 + warn "Calling `Lexer::Elem#[0]` is deprecated, please use `Lexer::Elem#pos` instead" + @pos + when 1 + warn "Calling `Lexer::Elem#[1]` is deprecated, please use `Lexer::Elem#event` instead" + @event + when 2 + warn "Calling `Lexer::Elem#[2]` is deprecated, please use `Lexer::Elem#tok` instead" + @tok + when 3 + warn "Calling `Lexer::Elem#[3]` is deprecated, please use `Lexer::Elem#state` instead" + @state + when 4 + warn "Calling `Lexer::Elem#[4]` is deprecated, please use `Lexer::Elem#message` instead" + @message + end + end + def inspect "#<#{self.class}: #{event}@#{pos[0]}:#{pos[1]}:#{state}: #{tok.inspect}#{": " if message}#{message}>" end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/