Class: SyntaxTree::Command
Overview
Command represents a method call with arguments and no parentheses. Note that Command nodes only happen when there is no explicit receiver for this method.
method argument
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- Args
-
the arguments being sent with the message.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#message ⇒ Object
readonly
- Const | Ident
-
the message being sent to the implicit receiver.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(message:, arguments:, location:, comments: []) ⇒ Command
constructor
A new instance of Command.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(message:, arguments:, location:, comments: []) ⇒ Command
Returns a new instance of Command.
3089 3090 3091 3092 3093 3094 |
# File 'lib/syntax_tree/node.rb', line 3089 def initialize(message:, arguments:, location:, comments: []) = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args
-
the arguments being sent with the message
3084 3085 3086 |
# File 'lib/syntax_tree/node.rb', line 3084 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3087 3088 3089 |
# File 'lib/syntax_tree/node.rb', line 3087 def comments @comments end |
#message ⇒ Object (readonly)
- Const | Ident
-
the message being sent to the implicit receiver
3081 3082 3083 |
# File 'lib/syntax_tree/node.rb', line 3081 def end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3096 3097 3098 |
# File 'lib/syntax_tree/node.rb', line 3096 def child_nodes [, arguments] end |
#deconstruct_keys(keys) ⇒ Object
3102 3103 3104 3105 3106 3107 3108 3109 |
# File 'lib/syntax_tree/node.rb', line 3102 def deconstruct_keys(keys) { message: , arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
3111 3112 3113 3114 3115 3116 3117 |
# File 'lib/syntax_tree/node.rb', line 3111 def format(q) q.group do q.format() q.text(" ") q.nest(.value.length + 1) { q.format(arguments) } end end |
#pretty_print(q) ⇒ Object
3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 |
# File 'lib/syntax_tree/node.rb', line 3119 def pretty_print(q) q.group(2, "(", ")") do q.text("command") q.breakable q.pp() q.breakable q.pp(arguments) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3133 3134 3135 3136 3137 3138 3139 3140 3141 |
# File 'lib/syntax_tree/node.rb', line 3133 def to_json(*opts) { type: :command, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |