class Prism::DefNode
Represents a method definition.
def method end ^^^^^^^^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 7961 def initialize(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @name = name @name_loc = name_loc @receiver = receiver @parameters = parameters @body = body @locals = locals @def_keyword_loc = def_keyword_loc @operator_loc = operator_loc @lparen_loc = lparen_loc @rparen_loc = rparen_loc @equal_loc = equal_loc @end_keyword_loc = end_keyword_loc end
Initialize a new DefNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 8100 def body @body end
Returns the body attribute.
Source
# File lib/prism/node.rb, line 8108 def locals @locals end
Returns the locals attribute.
Source
# File lib/prism/node.rb, line 8058 def name @name end
Returns the name attribute.
Source
# File lib/prism/node.rb, line 8092 def parameters @parameters end
Returns the parameters attribute.
Source
# File lib/prism/node.rb, line 8084 def receiver @receiver end
Returns the receiver attribute.
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 8117 def def_keyword_loc location = @def_keyword_loc return location if location.is_a?(Location) @def_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by def_keyword_loc.
Source
# File lib/prism/node.rb, line 8227 def end_keyword_loc location = @end_keyword_loc case location when nil nil when Location location else @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by end_keyword_loc.
Source
# File lib/prism/node.rb, line 8204 def equal_loc location = @equal_loc case location when nil nil when Location location else @equal_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Source
# File lib/prism/node.rb, line 8158 def lparen_loc location = @lparen_loc case location when nil nil when Location location else @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by lparen_loc.
Source
# File lib/prism/node.rb, line 8067 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Source
# File lib/prism/node.rb, line 8135 def operator_loc location = @operator_loc case location when nil nil when Location location else @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by operator_loc.
Source
# File lib/prism/node.rb, line 8181 def rparen_loc location = @rparen_loc case location when nil nil when Location location else @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by rparen_loc.
Node Interface
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 7992 def accept(visitor) visitor.visit_def_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 7997 def child_nodes [receiver, parameters, body] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 8020 def comment_targets [name_loc, *receiver, *parameters, *body, def_keyword_loc, *operator_loc, *lparen_loc, *rparen_loc, *equal_loc, *end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 8011 def compact_child_nodes compact = [] #: Array[Prism::node] compact << receiver if receiver compact << parameters if parameters compact << body if body compact end
Source
# File lib/prism/node.rb, line 8028 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, receiver: self.receiver, parameters: self.parameters, body: self.body, locals: self.locals, def_keyword_loc: self.def_keyword_loc, operator_loc: self.operator_loc, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, equal_loc: self.equal_loc, end_keyword_loc: self.end_keyword_loc) DefNode.new(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc) end
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 8002 def each_child_node return to_enum(:each_child_node) unless block_given? yield receiver if receiver yield parameters if parameters yield body if body end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 8126 def save_def_keyword_loc(repository) repository.enter(node_id, :def_keyword_loc) end
Save the def_keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8242 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil? end
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8219 def save_equal_loc(repository) repository.enter(node_id, :equal_loc) unless @equal_loc.nil? end
Save the equal_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8173 def save_lparen_loc(repository) repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil? end
Save the lparen_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8076 def save_name_loc(repository) repository.enter(node_id, :name_loc) end
Save the name_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8150 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) unless @operator_loc.nil? end
Save the operator_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8196 def save_rparen_loc(repository) repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil? end
Save the rparen_loc location using the given saved source so that it can be retrieved later.
Slicing
Public Instance Methods
Source
# File lib/prism/node.rb, line 8251 def def_keyword def_keyword_loc.slice end
Slice the location of def_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 8291 def end_keyword end_keyword_loc&.slice end
Slice the location of end_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 8283 def equal equal_loc&.slice end
Slice the location of equal_loc from the source.
Source
# File lib/prism/node.rb, line 8267 def lparen lparen_loc&.slice end
Slice the location of lparen_loc from the source.
Source
# File lib/prism/node.rb, line 8259 def operator operator_loc&.slice end
Slice the location of operator_loc from the source.
Source
# File lib/prism/node.rb, line 8275 def rparen rparen_loc&.slice end
Slice the location of rparen_loc from the source.