Class: Prism::Translation::Ripper::Lexer::State

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/translation/ripper/lexer.rb

Overview

:stopdoc:

Constant Summary collapse

STATES =

Instances are frozen and there are only a handful of them so we cache them here.

Hash.new { |h,k| h[k] = State.new(k) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ State



15
16
17
18
19
# File 'lib/prism/translation/ripper/lexer.rb', line 15

def initialize(i)
  @to_int = i
  @to_s = Ripper.lex_state_name(i)
  freeze
end

Instance Attribute Details

#to_intObject (readonly) Also known as: to_i

Returns the value of attribute to_int.



13
14
15
# File 'lib/prism/translation/ripper/lexer.rb', line 13

def to_int
  @to_int
end

#to_sObject (readonly) Also known as: inspect

Returns the value of attribute to_s.



13
14
15
# File 'lib/prism/translation/ripper/lexer.rb', line 13

def to_s
  @to_s
end

Class Method Details

.cached(i) ⇒ Object



45
46
47
# File 'lib/prism/translation/ripper/lexer.rb', line 45

def self.cached(i)
  STATES[i]
end

Instance Method Details

#&(i) ⇒ Object



36
# File 'lib/prism/translation/ripper/lexer.rb', line 36

def &(i) self.class.new(to_int & i) end

#==(i) ⇒ Object



35
# File 'lib/prism/translation/ripper/lexer.rb', line 35

def ==(i) super or to_int == i end

#[](index) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/prism/translation/ripper/lexer.rb', line 21

def [](index)
  case index
  when 0, :to_int
    @to_int
  when 1, :to_s
    @to_s
  else
    nil
  end
end

#allbits?(i) ⇒ Boolean



38
# File 'lib/prism/translation/ripper/lexer.rb', line 38

def allbits?(i) to_int.allbits?(i) end

#anybits?(i) ⇒ Boolean



39
# File 'lib/prism/translation/ripper/lexer.rb', line 39

def anybits?(i) to_int.anybits?(i) end

#nobits?(i) ⇒ Boolean



40
# File 'lib/prism/translation/ripper/lexer.rb', line 40

def nobits?(i) to_int.nobits?(i) end

#pretty_print(q) ⇒ Object



34
# File 'lib/prism/translation/ripper/lexer.rb', line 34

def pretty_print(q) q.text(to_s) end

#|(i) ⇒ Object



37
# File 'lib/prism/translation/ripper/lexer.rb', line 37

def |(i) self.class.new(to_int | i) end