Class: SyntaxTree::Yield0

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

Overview

Yield0 represents the bare yield keyword with no arguments.

yield

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Yield0.



11890
11891
11892
11893
11894
# File 'lib/syntax_tree/node.rb', line 11890

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



11888
11889
11890
# File 'lib/syntax_tree/node.rb', line 11888

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11885
11886
11887
# File 'lib/syntax_tree/node.rb', line 11885

def location
  @location
end

#valueObject (readonly)

String

the value of the keyword



11882
11883
11884
# File 'lib/syntax_tree/node.rb', line 11882

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



11896
11897
11898
# File 'lib/syntax_tree/node.rb', line 11896

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



11902
11903
11904
# File 'lib/syntax_tree/node.rb', line 11902

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



11906
11907
11908
# File 'lib/syntax_tree/node.rb', line 11906

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

#pretty_print(q) ⇒ Object



11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
# File 'lib/syntax_tree/node.rb', line 11910

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



11921
11922
11923
11924
11925
# File 'lib/syntax_tree/node.rb', line 11921

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