class SyntaxTree::DefNode
def object.method(param) result end
def method(param) result end
Def represents defining a regular method on the current self object.
def ===(other)
def ===(other) other.is_a?(DefNode) && target === other.target && operator === other.operator && name === other.name && params === other.params && bodystmt === other.bodystmt end
def accept(visitor)
def accept(visitor) visitor.visit_def(self) end
def arity
def arity params = self.params case params when Params params.arity when Paren params.contents.arity else 0..0 end end
def child_nodes
def child_nodes [target, operator, name, params, bodystmt] end
def copy(
def copy( target: nil, operator: nil, name: nil, params: nil, bodystmt: nil, location: nil ) node = DefNode.new( target: target || self.target, operator: operator || self.operator, name: name || self.name, params: params || self.params, bodystmt: bodystmt || self.bodystmt, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { target: target, operator: operator, name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end
def endless?
i.e. where the method body is defined using the `=` operator after the
Returns true if the method was found in the source in the "endless" form,
def endless? !bodystmt.is_a?(BodyStmt) end
def format(q)
def format(q) params = self.params bodystmt = self.bodystmt q.group do q.group do q.text("def") q.text(" ") if target || name.comments.empty? if target q.format(target) q.format(CallOperatorFormatter.new(operator), stackable: false) end q.format(name) case params when Paren q.format(params) when Params q.format(params) if !params.empty? || params.comments.any? end end if endless? q.text(" =") q.group do q.indent do q.breakable_space q.format(bodystmt) end end else unless bodystmt.empty? q.indent do q.breakable_force q.format(bodystmt) end end q.breakable_force q.text("end") end end end
def initialize(target:, operator:, name:, params:, bodystmt:, location:)
def initialize(target:, operator:, name:, params:, bodystmt:, location:) @target = target @operator = operator @name = name @params = params @bodystmt = bodystmt @location = location @comments = [] end