Class: SyntaxTree::BlockArg

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

BlockArg represents declaring a block parameter on a method definition.

def method(&block); end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, location:, comments: []) ⇒ BlockArg

Returns a new instance of BlockArg.



2590
2591
2592
2593
2594
# File 'lib/syntax_tree.rb', line 2590

def initialize(name:, location:, comments: [])
  @name = name
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2588
2589
2590
# File 'lib/syntax_tree.rb', line 2588

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



2585
2586
2587
# File 'lib/syntax_tree.rb', line 2585

def location
  @location
end

#nameObject (readonly)

Ident

the name of the block argument



2582
2583
2584
# File 'lib/syntax_tree.rb', line 2582

def name
  @name
end

Instance Method Details

#child_nodesObject



2596
2597
2598
# File 'lib/syntax_tree.rb', line 2596

def child_nodes
  [name]
end

#format(q) ⇒ Object



2600
2601
2602
2603
# File 'lib/syntax_tree.rb', line 2600

def format(q)
  q.text("&")
  q.format(name)
end

#pretty_print(q) ⇒ Object



2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
# File 'lib/syntax_tree.rb', line 2605

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("blockarg")

    q.breakable
    q.pp(name)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



2616
2617
2618
2619
2620
# File 'lib/syntax_tree.rb', line 2616

def to_json(*opts)
  { type: :blockarg, name: name, loc: location, cmts: comments }.to_json(
    *opts
  )
end