Class: WadlerExample::Tree
- Inherits:
-
Object
- Object
- WadlerExample::Tree
- Defined in:
- lib/prettyprint.rb
Overview
:nodoc:
Instance Method Summary collapse
- #altshow(q) ⇒ Object
-
#initialize(string, *children) ⇒ Tree
constructor
A new instance of Tree.
- #show(q) ⇒ Object
Constructor Details
#initialize(string, *children) ⇒ Tree
Returns a new instance of Tree.
565 566 567 568 |
# File 'lib/prettyprint.rb', line 565 def initialize(string, *children) @string = string @children = children end |
Instance Method Details
#altshow(q) ⇒ Object
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/prettyprint.rb', line 594 def altshow(q) q.group { q.text @string unless @children.empty? q.text '[' q.nest(2) { q.breakable first = true @children.each {|t| if first first = false else q.text ',' q.breakable end t.altshow(q) } } q.breakable q.text ']' end } end |
#show(q) ⇒ Object
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/prettyprint.rb', line 570 def show(q) q.group { q.text @string q.nest(@string.length) { unless @children.empty? q.text '[' q.nest(1) { first = true @children.each {|t| if first first = false else q.text ',' q.breakable end t.show(q) } } q.text ']' end } } end |