Class: SyntaxTree::RBS::NameAndArgs
- Inherits:
-
Object
- Object
- SyntaxTree::RBS::NameAndArgs
- Defined in:
- lib/syntax_tree/rbs/utils.rb
Overview
Certain nodes are names with optional arguments attached, as in Array. We handle all of that printing centralized here.
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(node) ⇒ NameAndArgs
constructor
A new instance of NameAndArgs.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize(node) ⇒ NameAndArgs
Returns a new instance of NameAndArgs.
96 97 98 |
# File 'lib/syntax_tree/rbs/utils.rb', line 96 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
94 95 96 |
# File 'lib/syntax_tree/rbs/utils.rb', line 94 def node @node end |
Instance Method Details
#format(q) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/syntax_tree/rbs/utils.rb', line 100 def format(q) q.group do node.name.format(q) if node.args.any? q.text("[") q.seplist(node.args, -> { q.text(", ") }) { |arg| arg.format(q) } q.text("]") end end end |
#pretty_print(q) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/syntax_tree/rbs/utils.rb', line 112 def pretty_print(q) q.breakable q.pp(node.name) if node.args.any? q.breakable q.pp(node.args) end end |