Class: ORB::Token
- Inherits:
-
Object
- Object
- ORB::Token
- Defined in:
- lib/orb/token.rb
Overview
A simple PORO to represent a token.
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type, value, meta = {}) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, _include_private = false) ⇒ Boolean
- #set_meta(key, value) ⇒ Object
- #to_s ⇒ Object
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, = {}) @type = type @value = value = @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 .has_key?(method.to_sym) [method.to_sym] else super end end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
37 38 39 |
# File 'lib/orb/token.rb', line 37 def line @line end |
#meta ⇒ Object
Returns the value of attribute meta.
6 7 8 |
# File 'lib/orb/token.rb', line 6 def end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/orb/token.rb', line 6 def type @type end |
#value ⇒ Object
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 && == other. end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/orb/token.rb', line 39 def inspect to_s end |
#respond_to_missing?(method, _include_private = false) ⇒ Boolean
19 20 21 |
# File 'lib/orb/token.rb', line 19 def respond_to_missing?(method, _include_private = false) .has_key?(method.to_sym) end |
#set_meta(key, value) ⇒ Object
15 16 17 |
# File 'lib/orb/token.rb', line 15 def (key, value) [key.to_sym] = value end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/orb/token.rb', line 43 def to_s "#<ORB::Token[#{type}] meta=#{meta.inspect} value=#{value.inspect}>" end |