Class: SyntaxTree::Kw
Overview
Kw represents the use of a keyword. It can be almost anywhere in the syntax tree, so you end up seeing it quite a lot.
if value
end
In the above example, there would be two Kw nodes: one for the if and one for the end. Note that anything that matches the list of keywords in Ruby will use a Kw, so if you use a keyword in a symbol literal for instance:
:if
then the contents of the symbol node will contain a Kw node.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#name ⇒ Object
readonly
- Symbol
-
the symbol version of the value.
-
#value ⇒ Object
readonly
- String
-
the value of the keyword.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ Kw
constructor
A new instance of Kw.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ Kw
Returns a new instance of Kw.
6827 6828 6829 6830 6831 6832 |
# File 'lib/syntax_tree/node.rb', line 6827 def initialize(value:, location:) @value = value @name = value.to_sym @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6825 6826 6827 |
# File 'lib/syntax_tree/node.rb', line 6825 def comments @comments end |
#name ⇒ Object (readonly)
- Symbol
-
the symbol version of the value
6822 6823 6824 |
# File 'lib/syntax_tree/node.rb', line 6822 def name @name end |
#value ⇒ Object (readonly)
- String
-
the value of the keyword
6819 6820 6821 |
# File 'lib/syntax_tree/node.rb', line 6819 def value @value end |
Instance Method Details
#===(other) ⇒ Object
6860 6861 6862 |
# File 'lib/syntax_tree/node.rb', line 6860 def ===(other) other.is_a?(Kw) && value === other.value end |
#accept(visitor) ⇒ Object
6834 6835 6836 |
# File 'lib/syntax_tree/node.rb', line 6834 def accept(visitor) visitor.visit_kw(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6838 6839 6840 |
# File 'lib/syntax_tree/node.rb', line 6838 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
6842 6843 6844 6845 6846 6847 6848 |
# File 'lib/syntax_tree/node.rb', line 6842 def copy(value: nil, location: nil) node = Kw.new(value: value || self.value, location: location || self.location) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
6852 6853 6854 |
# File 'lib/syntax_tree/node.rb', line 6852 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6856 6857 6858 |
# File 'lib/syntax_tree/node.rb', line 6856 def format(q) q.text(value) end |