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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ Kw
Returns a new instance of Kw.
6890 6891 6892 6893 6894 6895 |
# File 'lib/syntax_tree/node.rb', line 6890 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
6888 6889 6890 |
# File 'lib/syntax_tree/node.rb', line 6888 def comments @comments end |
#name ⇒ Object (readonly)
- Symbol
-
the symbol version of the value
6885 6886 6887 |
# File 'lib/syntax_tree/node.rb', line 6885 def name @name end |
#value ⇒ Object (readonly)
- String
-
the value of the keyword
6882 6883 6884 |
# File 'lib/syntax_tree/node.rb', line 6882 def value @value end |
Instance Method Details
#===(other) ⇒ Object
6923 6924 6925 |
# File 'lib/syntax_tree/node.rb', line 6923 def ===(other) other.is_a?(Kw) && value === other.value end |
#accept(visitor) ⇒ Object
6897 6898 6899 |
# File 'lib/syntax_tree/node.rb', line 6897 def accept(visitor) visitor.visit_kw(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6901 6902 6903 |
# File 'lib/syntax_tree/node.rb', line 6901 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
6905 6906 6907 6908 6909 6910 6911 |
# File 'lib/syntax_tree/node.rb', line 6905 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
6915 6916 6917 |
# File 'lib/syntax_tree/node.rb', line 6915 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6919 6920 6921 |
# File 'lib/syntax_tree/node.rb', line 6919 def format(q) q.text(value) end |