Class: SyntaxTree::DefEndless
Overview
DefEndless represents defining a single-line method since Ruby 3.0+.
def method = result
Instance Attribute Summary collapse
-
#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.
-
#paren ⇒ Object
readonly
- nil | Params | Paren
-
the parameter declaration for the method.
-
#statement ⇒ Object
readonly
- untyped
-
the expression to be executed by the method.
-
#target ⇒ Object
readonly
- untyped
-
the target where the method is being defined.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, operator:, name:, paren:, statement:, location:, comments: []) ⇒ DefEndless
constructor
A new instance of DefEndless.
Methods inherited from Node
Constructor Details
#initialize(target:, operator:, name:, paren:, statement:, location:, comments: []) ⇒ DefEndless
Returns a new instance of DefEndless.
3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 |
# File 'lib/syntax_tree/node.rb', line 3064 def initialize( target:, operator:, name:, paren:, statement:, location:, comments: [] ) @target = target @operator = operator @name = name @paren = paren @statement = statement @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3062 3063 3064 |
# File 'lib/syntax_tree/node.rb', line 3062 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3053 3054 3055 |
# File 'lib/syntax_tree/node.rb', line 3053 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3050 3051 3052 |
# File 'lib/syntax_tree/node.rb', line 3050 def operator @operator end |
#paren ⇒ Object (readonly)
- nil | Params | Paren
-
the parameter declaration for the method
3056 3057 3058 |
# File 'lib/syntax_tree/node.rb', line 3056 def paren @paren end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed by the method
3059 3060 3061 |
# File 'lib/syntax_tree/node.rb', line 3059 def statement @statement end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3047 3048 3049 |
# File 'lib/syntax_tree/node.rb', line 3047 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3082 3083 3084 |
# File 'lib/syntax_tree/node.rb', line 3082 def accept(visitor) visitor.visit_def_endless(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3086 3087 3088 |
# File 'lib/syntax_tree/node.rb', line 3086 def child_nodes [target, operator, name, paren, statement] end |
#deconstruct_keys(keys) ⇒ Object
3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 |
# File 'lib/syntax_tree/node.rb', line 3092 def deconstruct_keys(keys) { target: target, operator: operator, name: name, paren: paren, statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 |
# File 'lib/syntax_tree/node.rb', line 3104 def format(q) q.group do q.text("def ") if target q.format(target) q.format(CallOperatorFormatter.new(operator), stackable: false) end q.format(name) if paren params = paren params = params.contents if params.is_a?(Paren) q.format(paren) unless params.empty? end q.text(" =") q.group do q.indent do q.breakable q.format(statement) end end end end |