Class: ORB::Token

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

Overview

A simple PORO to represent a token.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, meta = {}) ⇒ Token

Returns a new instance of Token.



8
9
10
11
12
13
# File 'lib/orb/token.rb', line 8

def initialize(type, value, meta = {})
  @type = type
  @value = value
  @meta = meta
  @line = line || 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/orb/token.rb', line 23

def method_missing(method, *args, &block)
  if meta.has_key?(method.to_sym)
    meta[method.to_sym]
  else
    super
  end
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



37
38
39
# File 'lib/orb/token.rb', line 37

def line
  @line
end

#metaObject

Returns the value of attribute meta.



6
7
8
# File 'lib/orb/token.rb', line 6

def meta
  @meta
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/orb/token.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/orb/token.rb', line 6

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
# File 'lib/orb/token.rb', line 31

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

#inspectObject



39
40
41
# File 'lib/orb/token.rb', line 39

def inspect
  to_s
end

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/orb/token.rb', line 19

def respond_to_missing?(method, _include_private = false)
  meta.has_key?(method.to_sym)
end

#set_meta(key, value) ⇒ Object



15
16
17
# File 'lib/orb/token.rb', line 15

def set_meta(key, value)
  meta[key.to_sym] = value
end

#to_sObject



43
44
45
# File 'lib/orb/token.rb', line 43

def to_s
  "#<ORB::Token[#{type}] meta=#{meta.inspect} value=#{value.inspect}>"
end