Class: IRB::Color::SymbolState (Ruby 2.7.5)
Description: Class : IRB::Color::SymbolState - Ruby 2.7.5

### Home Classes Methods

### In Files

- irb/color.rb

### Parent

Object

### Methods

- ::new
- #scan_token

### Class/Module Index

Quicksearch

- Binding
- IRB::Abort
- IRB::Canvas
- IRB::Color
- IRB::Color::SymbolState
- IRB::Context
- IRB::ContextExtender
- IRB::ExtendCommandBundle
- IRB::FileInputMethod
- IRB::Frame
- IRB::Frame::FrameOverflow
- IRB::Frame::FrameUnderflow
- IRB::History
- IRB::InputMethod
- IRB::Inspector
- IRB::Irb
- IRB::IrbLoader
- IRB::JobManager
- IRB::LoadAbort
- IRB::MethodExtender
- IRB::Notifier
- IRB::Notifier::AbstractNotifier
- IRB::Notifier::CompositeNotifier
- IRB::Notifier::ErrUndefinedNotifier
- IRB::Notifier::ErrUnrecognizedLevel
- IRB::Notifier::LeveledNotifier
- IRB::Notifier::NoMsgNotifier
- IRB::OutputMethod
- IRB::OutputMethod::NotImplementedError
- IRB::ReadlineInputMethod
- IRB::ReidlineInputMethod
- IRB::RubyModel
- IRB::StdioInputMethod
- IRB::StdioOutputMethod
- IRB::Vec
- IRB::WorkSpace
- Object
- XMP
- XMP::StringInputMethod

No matching classes.

# IRB::Color::SymbolState

A class to manage a state to know whether the current token is for Symbol or not.

### Public Class Methods

new() click to toggle source

                   # File irb/color.rb, line 203
    def initialize
      # Push `true` to detect Symbol. `false` to increase the nest level for non-Symbol.
      @stack = []
    end

### Public Instance Methods

scan_token(token) click to toggle source

Return true if the token is a part of Symbol.

                   # File irb/color.rb, line 209
    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
        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