зеркало из https://github.com/github/ruby.git
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.
This commit is contained in:
Родитель
2b22c93533
Коммит
8944009be7
|
@ -62,6 +62,17 @@ class Ripper
|
|||
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
|
|||
@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
|
||||
|
|
Загрузка…
Ссылка в новой задаче