Class: YARP::DefNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::DefNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a method definition.
def method
end
^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: Node?.
-
#def_keyword_loc ⇒ Object
readonly
attr_reader def_keyword_loc: Location.
-
#end_keyword_loc ⇒ Object
readonly
attr_reader end_keyword_loc: Location?.
-
#equal_loc ⇒ Object
readonly
attr_reader equal_loc: Location?.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#lparen_loc ⇒ Object
readonly
attr_reader lparen_loc: Location?.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#name_loc ⇒ Object
readonly
attr_reader name_loc: Location.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location?.
-
#parameters ⇒ Object
readonly
attr_reader parameters: ParametersNode?.
-
#receiver ⇒ Object
readonly
attr_reader receiver: Node?.
-
#rparen_loc ⇒ Object
readonly
attr_reader rparen_loc: Location?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> DefNode.
- #deconstruct_keys(keys) ⇒ Object
-
#def_keyword ⇒ Object
def def_keyword: () -> String.
-
#end_keyword ⇒ Object
def end_keyword: () -> String?.
-
#equal ⇒ Object
def equal: () -> String?.
-
#initialize(name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) ⇒ DefNode
constructor
def initialize: (name: Symbol, name_loc: Location, receiver: Node?, parameters: ParametersNode?, body: Node?, locals: Array, def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#lparen ⇒ Object
def lparen: () -> String?.
-
#operator ⇒ Object
def operator: () -> String?.
-
#rparen ⇒ Object
def rparen: () -> String?.
Constructor Details
#initialize(name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) ⇒ DefNode
def initialize: (name: Symbol, name_loc: Location, receiver: Node?, parameters: ParametersNode?, body: Node?, locals: Array, def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location?, location: Location) -> void
3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 |
# File 'lib/yarp/node.rb', line 3439 def initialize(name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) @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 @location = location end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: Node?
3415 3416 3417 |
# File 'lib/yarp/node.rb', line 3415 def body @body end |
#def_keyword_loc ⇒ Object (readonly)
attr_reader def_keyword_loc: Location
3421 3422 3423 |
# File 'lib/yarp/node.rb', line 3421 def def_keyword_loc @def_keyword_loc end |
#end_keyword_loc ⇒ Object (readonly)
attr_reader end_keyword_loc: Location?
3436 3437 3438 |
# File 'lib/yarp/node.rb', line 3436 def end_keyword_loc @end_keyword_loc end |
#equal_loc ⇒ Object (readonly)
attr_reader equal_loc: Location?
3433 3434 3435 |
# File 'lib/yarp/node.rb', line 3433 def equal_loc @equal_loc end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
3418 3419 3420 |
# File 'lib/yarp/node.rb', line 3418 def locals @locals end |
#lparen_loc ⇒ Object (readonly)
attr_reader lparen_loc: Location?
3427 3428 3429 |
# File 'lib/yarp/node.rb', line 3427 def lparen_loc @lparen_loc end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
3403 3404 3405 |
# File 'lib/yarp/node.rb', line 3403 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location
3406 3407 3408 |
# File 'lib/yarp/node.rb', line 3406 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location?
3424 3425 3426 |
# File 'lib/yarp/node.rb', line 3424 def operator_loc @operator_loc end |
#parameters ⇒ Object (readonly)
attr_reader parameters: ParametersNode?
3412 3413 3414 |
# File 'lib/yarp/node.rb', line 3412 def parameters @parameters end |
#receiver ⇒ Object (readonly)
attr_reader receiver: Node?
3409 3410 3411 |
# File 'lib/yarp/node.rb', line 3409 def receiver @receiver end |
#rparen_loc ⇒ Object (readonly)
attr_reader rparen_loc: Location?
3430 3431 3432 |
# File 'lib/yarp/node.rb', line 3430 def rparen_loc @rparen_loc end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
3456 3457 3458 |
# File 'lib/yarp/node.rb', line 3456 def accept(visitor) visitor.visit_def_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
3461 3462 3463 |
# File 'lib/yarp/node.rb', line 3461 def child_nodes [receiver, parameters, body] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
3466 3467 3468 |
# File 'lib/yarp/node.rb', line 3466 def comment_targets [name_loc, *receiver, *parameters, *body, def_keyword_loc, *operator_loc, *lparen_loc, *rparen_loc, *equal_loc, *end_keyword_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> DefNode
3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 |
# File 'lib/yarp/node.rb', line 3471 def copy(**params) DefNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:receiver) { receiver }, params.fetch(:parameters) { parameters }, params.fetch(:body) { body }, params.fetch(:locals) { locals }, params.fetch(:def_keyword_loc) { def_keyword_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:lparen_loc) { lparen_loc }, params.fetch(:rparen_loc) { rparen_loc }, params.fetch(:equal_loc) { equal_loc }, params.fetch(:end_keyword_loc) { end_keyword_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
3493 3494 3495 |
# File 'lib/yarp/node.rb', line 3493 def deconstruct_keys(keys) { 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, location: location } end |
#def_keyword ⇒ Object
def def_keyword: () -> String
3498 3499 3500 |
# File 'lib/yarp/node.rb', line 3498 def def_keyword def_keyword_loc.slice end |
#end_keyword ⇒ Object
def end_keyword: () -> String?
3523 3524 3525 |
# File 'lib/yarp/node.rb', line 3523 def end_keyword end_keyword_loc&.slice end |
#equal ⇒ Object
def equal: () -> String?
3518 3519 3520 |
# File 'lib/yarp/node.rb', line 3518 def equal equal_loc&.slice end |
#inspect(inspector = NodeInspector.new) ⇒ Object
3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 |
# File 'lib/yarp/node.rb', line 3527 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── name: #{name.inspect}\n" inspector << "├── name_loc: #{inspector.location(name_loc)}\n" if (receiver = self.receiver).nil? inspector << "├── receiver: ∅\n" else inspector << "├── receiver:\n" inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end if (parameters = self.parameters).nil? inspector << "├── parameters: ∅\n" else inspector << "├── parameters:\n" inspector << parameters.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end if (body = self.body).nil? inspector << "├── body: ∅\n" else inspector << "├── body:\n" inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── locals: #{locals.inspect}\n" inspector << "├── def_keyword_loc: #{inspector.location(def_keyword_loc)}\n" inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" inspector << "├── rparen_loc: #{inspector.location(rparen_loc)}\n" inspector << "├── equal_loc: #{inspector.location(equal_loc)}\n" inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" inspector.to_str end |
#lparen ⇒ Object
def lparen: () -> String?
3508 3509 3510 |
# File 'lib/yarp/node.rb', line 3508 def lparen lparen_loc&.slice end |
#operator ⇒ Object
def operator: () -> String?
3503 3504 3505 |
# File 'lib/yarp/node.rb', line 3503 def operator operator_loc&.slice end |
#rparen ⇒ Object
def rparen: () -> String?
3513 3514 3515 |
# File 'lib/yarp/node.rb', line 3513 def rparen rparen_loc&.slice end |