Class: Prism::Node
- Inherits:
-
Object
- Object
- Prism::Node
- Defined in:
- lib/masamune/abstract_syntax_tree/prism/node_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #comment? ⇒ Boolean
- #line_number ⇒ Object
-
#token_location ⇒ Object
#location provides helpful information for the source code of a node as a whole, but in Masamune we generally want the token value itself, so we primarily get the token value’s location.
-
#token_value ⇒ Object
The source code of Prism nodes can be retrieved by calling #slice.
Class Method Details
Instance Method Details
#comment? ⇒ Boolean
3 |
# File 'lib/masamune/abstract_syntax_tree/prism/node_extensions.rb', line 3 def comment? = false |
#line_number ⇒ Object
10 11 12 |
# File 'lib/masamune/abstract_syntax_tree/prism/node_extensions.rb', line 10 def line_number token_location.start_line end |
#token_location ⇒ Object
#location provides helpful information for the source code of a node as a whole, but in Masamune we generally want the token value itself, so we primarily get the token value’s location.
16 17 18 |
# File 'lib/masamune/abstract_syntax_tree/prism/node_extensions.rb', line 16 def token_location location end |
#token_value ⇒ Object
The source code of Prism nodes can be retrieved by calling #slice. However, the output tends to vary from node to node, and other methods like ‘name`, `message`, etc. are available in Prism nodes which means you have to know exactly which method to call the get the results you want.
The ‘token` method simplifies all of this, and just gives you the variable, method name, etc. in String form by just calling `token_value`.
27 28 29 |
# File 'lib/masamune/abstract_syntax_tree/prism/node_extensions.rb', line 27 def token_value content end |