类 IRB::Color::SymbolState

一个用于管理状态的类,用于判断当前标记是否属于 Symbol

公共类方法

new() 点击切换源代码
# File lib/irb/color.rb, line 230
def initialize
  # Push `true` to detect Symbol. `false` to increase the nest level for non-Symbol.
  @stack = []
end

公共实例方法

scan_token(token) 点击切换源代码

如果标记是 Symbol 的一部分,则返回 true。

# File lib/irb/color.rb, line 236
def scan_token(token)
  prev_state = @stack.last
  case token
  when :on_symbeg, :on_symbols_beg, :on_qsymbols_beg
    @stack << true
  when :on_ident, :on_op, :on_const, :on_ivar, :on_cvar, :on_gvar, :on_kw, :on_backtick
    if @stack.last # Pop only when it's Symbol
      @stack.pop
      return prev_state
    end
  when :on_tstring_beg
    @stack << false
  when :on_embexpr_beg
    @stack << false
    return prev_state
  when :on_tstring_end # :on_tstring_end may close Symbol
    @stack.pop
    return prev_state
  when :on_embexpr_end
    @stack.pop
  end
  @stack.last
end