Class: SyntaxTree::CommandCall
Overview
CommandCall represents a method call on an object with arguments and no parentheses.
object.method argument
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- nil | Args
-
the arguments going along with the message.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#message ⇒ Object
readonly
- Const | Ident | Op
-
the message being send.
-
#operator ⇒ Object
readonly
- :“::” | Op | Period
-
the operator used to send the message.
-
#receiver ⇒ Object
readonly
- untyped
-
the receiver of the message.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ CommandCall
constructor
A new instance of CommandCall.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ CommandCall
Returns a new instance of CommandCall.
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 |
# File 'lib/syntax_tree/node.rb', line 3023 def initialize( receiver:, operator:, message:, arguments:, location:, comments: [] ) @receiver = receiver @operator = operator = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | Args
-
the arguments going along with the message
3018 3019 3020 |
# File 'lib/syntax_tree/node.rb', line 3018 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3021 3022 3023 |
# File 'lib/syntax_tree/node.rb', line 3021 def comments @comments end |
#message ⇒ Object (readonly)
- Const | Ident | Op
-
the message being send
3015 3016 3017 |
# File 'lib/syntax_tree/node.rb', line 3015 def end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator used to send the message
3012 3013 3014 |
# File 'lib/syntax_tree/node.rb', line 3012 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the message
3009 3010 3011 |
# File 'lib/syntax_tree/node.rb', line 3009 def receiver @receiver end |
Instance Method Details
#accept(visitor) ⇒ Object
3039 3040 3041 |
# File 'lib/syntax_tree/node.rb', line 3039 def accept(visitor) visitor.visit_command_call(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3043 3044 3045 |
# File 'lib/syntax_tree/node.rb', line 3043 def child_nodes [receiver, , arguments] end |
#deconstruct_keys(_keys) ⇒ Object
3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 |
# File 'lib/syntax_tree/node.rb', line 3049 def deconstruct_keys(_keys) { receiver: receiver, operator: operator, message: , arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 |
# File 'lib/syntax_tree/node.rb', line 3060 def format(q) q.group do doc = q.nest(0) do q.format(receiver) # If there are leading comments on the message then we know we have # a newline in the source that is forcing these things apart. In # this case we will have to use a trailing operator. if .comments.any?(&:leading?) q.format(CallOperatorFormatter.new(operator), stackable: false) q.indent do q.breakable("") q.format() end else q.format(CallOperatorFormatter.new(operator), stackable: false) q.format() end end case arguments in Args[parts: [IfOp]] q.if_flat { q.text(" ") } q.format(arguments) in Args q.text(" ") q.nest(argument_alignment(q, doc)) { q.format(arguments) } else # If there are no arguments, print nothing. end end end |