Class: SyntaxTree::Return0

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

Overview

Return0 represents the bare return keyword with no arguments.

return

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Return0

Returns a new instance of Return0.



10658
10659
10660
10661
10662
# File 'lib/syntax_tree.rb', line 10658

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10656
10657
10658
# File 'lib/syntax_tree.rb', line 10656

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10653
10654
10655
# File 'lib/syntax_tree.rb', line 10653

def location
  @location
end

#valueObject (readonly)

String

the value of the keyword



10650
10651
10652
# File 'lib/syntax_tree.rb', line 10650

def value
  @value
end

Instance Method Details

#child_nodesObject



10664
10665
10666
# File 'lib/syntax_tree.rb', line 10664

def child_nodes
  []
end

#format(q) ⇒ Object



10668
10669
10670
# File 'lib/syntax_tree.rb', line 10668

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
# File 'lib/syntax_tree.rb', line 10672

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



10683
10684
10685
10686
10687
# File 'lib/syntax_tree.rb', line 10683

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