Class: Ast::Token
- Inherits:
-
Object
- Object
- Ast::Token
- Defined in:
- lib/ast_ast/token.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.valid?(arr) ⇒ Boolean
Check whether an array given is valid, ie.
Instance Method Summary collapse
-
#initialize(type, value) ⇒ Token
constructor
A new instance of Token.
-
#inspect ⇒ Object
Make #inspect show something a bit prettier.
-
#to_a ⇒ Array
Turn the Token to an Array.
-
#to_s ⇒ String
Turn the Token to a String, similar to an array.
Constructor Details
#initialize(type, value) ⇒ Token
Returns a new instance of Token.
5 6 7 8 |
# File 'lib/ast_ast/token.rb', line 5 def initialize(type, value) @type = type @value = value end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/ast_ast/token.rb', line 3 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/ast_ast/token.rb', line 3 def value @value end |
Class Method Details
.valid?(arr) ⇒ Boolean
Check whether an array given is valid, ie. it has a symbol then one or no objects only.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ast_ast/token.rb', line 21 def self.valid?(arr) if arr.is_a? Array if arr.nil? || arr.size > 2 || arr.size == 0 false elsif !arr[0].is_a?(Symbol) false else true end elsif arr.is_a? Token true else false end end |
Instance Method Details
#inspect ⇒ Object
Make #inspect show something a bit prettier
72 73 74 |
# File 'lib/ast_ast/token.rb', line 72 def inspect self.to_s end |
#to_a ⇒ Array
Turn the Token to an Array.
63 64 65 66 67 68 69 |
# File 'lib/ast_ast/token.rb', line 63 def to_a if @value.nil? [@type] else [@type, @value] end end |
#to_s ⇒ String
Turn the Token to a String, similar to an array.
46 47 48 49 50 51 52 |
# File 'lib/ast_ast/token.rb', line 46 def to_s if @value.nil? "<#{@type.inspect}>" else "<#{@type.inspect}, #{@value.inspect}>" end end |