Class: SyntaxTree::Defs
Overview
Defs represents defining a singleton method on an object.
def object.method(param) result end
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the expressions to be executed by the method.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#name ⇒ Object
readonly
- Backtick | Const | Ident | Kw | Op
-
the name of the method.
-
#operator ⇒ Object
readonly
- Op | Period
-
the operator being used to declare the method.
-
#params ⇒ Object
readonly
- Params | Paren
-
the parameter declaration for the method.
-
#target ⇒ Object
readonly
- untyped
-
the target where the method is being defined.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, operator:, name:, params:, bodystmt:, location:, comments: []) ⇒ Defs
constructor
A new instance of Defs.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(target:, operator:, name:, params:, bodystmt:, location:, comments: []) ⇒ Defs
Returns a new instance of Defs.
3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 |
# File 'lib/syntax_tree/node.rb', line 3985 def initialize( target:, operator:, name:, params:, bodystmt:, location:, comments: [] ) @target = target @operator = operator @name = name @params = params @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed by the method
3980 3981 3982 |
# File 'lib/syntax_tree/node.rb', line 3980 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3983 3984 3985 |
# File 'lib/syntax_tree/node.rb', line 3983 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3974 3975 3976 |
# File 'lib/syntax_tree/node.rb', line 3974 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3971 3972 3973 |
# File 'lib/syntax_tree/node.rb', line 3971 def operator @operator end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3977 3978 3979 |
# File 'lib/syntax_tree/node.rb', line 3977 def params @params end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3968 3969 3970 |
# File 'lib/syntax_tree/node.rb', line 3968 def target @target end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
4003 4004 4005 |
# File 'lib/syntax_tree/node.rb', line 4003 def child_nodes [target, operator, name, params, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 |
# File 'lib/syntax_tree/node.rb', line 4009 def deconstruct_keys(keys) { target: target, operator: operator, name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 |
# File 'lib/syntax_tree/node.rb', line 4021 def format(q) q.group do q.group do q.text("def ") q.format(target) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) q.format(params) if !params.is_a?(Params) || !params.empty? end unless bodystmt.empty? q.indent do q.breakable(force: true) q.format(bodystmt) end end q.breakable(force: true) q.text("end") end end |
#pretty_print(q) ⇒ Object
4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 |
# File 'lib/syntax_tree/node.rb', line 4043 def pretty_print(q) q.group(2, "(", ")") do q.text("defs") q.breakable q.pp(target) q.breakable q.pp(operator) q.breakable q.pp(name) q.breakable q.pp(params) q.breakable q.pp(bodystmt) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 |
# File 'lib/syntax_tree/node.rb', line 4066 def to_json(*opts) { type: :defs, target: target, op: operator, name: name, params: params, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |