Class: Lexr::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/lexr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, type = nil) ⇒ Token

Returns a new instance of Token.



51
52
53
# File 'lib/lexr.rb', line 51

def initialize(value, type = nil)
  @value, @type = value, type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



49
50
51
# File 'lib/lexr.rb', line 49

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



49
50
51
# File 'lib/lexr.rb', line 49

def value
  @value
end

Class Method Details

.method_missing(sym, *args) ⇒ Object



55
56
57
# File 'lib/lexr.rb', line 55

def self.method_missing(sym, *args)
  self.new(args.first, sym)
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
# File 'lib/lexr.rb', line 63

def ==(other)
  @type == other.type && @value == other.value
end

#to_sObject



59
60
61
# File 'lib/lexr.rb', line 59

def to_s
  "#{type}(#{value})"
end