Class: SyntaxTree::CommandCall
- Inherits:
-
Object
- Object
- SyntaxTree::CommandCall
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of 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.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ CommandCall
constructor
A new instance of CommandCall.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ CommandCall
Returns a new instance of CommandCall.
3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 |
# File 'lib/syntax_tree.rb', line 3888 def initialize( receiver:, operator:, message:, arguments:, location:, comments: [] ) @receiver = receiver @operator = operator @message = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | Args
-
the arguments going along with the message
3880 3881 3882 |
# File 'lib/syntax_tree.rb', line 3880 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3886 3887 3888 |
# File 'lib/syntax_tree.rb', line 3886 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3883 3884 3885 |
# File 'lib/syntax_tree.rb', line 3883 def location @location end |
#message ⇒ Object (readonly)
- Const | Ident | Op
-
the message being send
3877 3878 3879 |
# File 'lib/syntax_tree.rb', line 3877 def @message end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator used to send the message
3874 3875 3876 |
# File 'lib/syntax_tree.rb', line 3874 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the message
3871 3872 3873 |
# File 'lib/syntax_tree.rb', line 3871 def receiver @receiver end |
Instance Method Details
#child_nodes ⇒ Object
3904 3905 3906 |
# File 'lib/syntax_tree.rb', line 3904 def child_nodes [receiver, , arguments] end |
#format(q) ⇒ Object
3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 |
# File 'lib/syntax_tree.rb', line 3908 def format(q) q.group do doc = q.nest(0) do q.format(receiver) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format() end if arguments q.text(" ") q.nest(argument_alignment(q, doc)) { q.format(arguments) } end end end |
#pretty_print(q) ⇒ Object
3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 |
# File 'lib/syntax_tree.rb', line 3924 def pretty_print(q) q.group(2, "(", ")") do q.text("command_call") q.breakable q.pp(receiver) q.breakable q.pp(operator) q.breakable q.pp() if arguments q.breakable q.pp(arguments) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 |
# File 'lib/syntax_tree.rb', line 3946 def to_json(*opts) { type: :command_call, receiver: receiver, op: operator, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |