Class: SyntaxTree::FlowControlFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::FlowControlFormatter
- Defined in:
- lib/syntax_tree.rb
Overview
Formats either a Break or Next node.
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
- String
-
the keyword to print.
-
#node ⇒ Object
readonly
- Break | Next
-
the node being formatted.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(keyword, node) ⇒ FlowControlFormatter
constructor
A new instance of FlowControlFormatter.
Constructor Details
#initialize(keyword, node) ⇒ FlowControlFormatter
Returns a new instance of FlowControlFormatter.
2842 2843 2844 2845 |
# File 'lib/syntax_tree.rb', line 2842 def initialize(keyword, node) @keyword = keyword @node = node end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the keyword to print
2837 2838 2839 |
# File 'lib/syntax_tree.rb', line 2837 def keyword @keyword end |
#node ⇒ Object (readonly)
- Break | Next
-
the node being formatted
2840 2841 2842 |
# File 'lib/syntax_tree.rb', line 2840 def node @node end |
Instance Method Details
#format(q) ⇒ Object
2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 |
# File 'lib/syntax_tree.rb', line 2847 def format(q) arguments = node.arguments q.group do q.text(keyword) if arguments.parts.any? if arguments.parts.length == 1 && arguments.parts.first.is_a?(Paren) q.format(arguments) else q.text(" ") q.nest(keyword.length + 1) { q.format(arguments) } end end end end |