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.
3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 |
# File 'lib/syntax_tree.rb', line 3767 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
3759 3760 3761 |
# File 'lib/syntax_tree.rb', line 3759 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3765 3766 3767 |
# File 'lib/syntax_tree.rb', line 3765 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3762 3763 3764 |
# File 'lib/syntax_tree.rb', line 3762 def location @location end |
#message ⇒ Object (readonly)
- Const | Ident | Op
-
the message being send
3756 3757 3758 |
# File 'lib/syntax_tree.rb', line 3756 def @message end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator used to send the message
3753 3754 3755 |
# File 'lib/syntax_tree.rb', line 3753 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the message
3750 3751 3752 |
# File 'lib/syntax_tree.rb', line 3750 def receiver @receiver end |
Instance Method Details
#child_nodes ⇒ Object
3783 3784 3785 |
# File 'lib/syntax_tree.rb', line 3783 def child_nodes [receiver, , arguments] end |
#format(q) ⇒ Object
3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 |
# File 'lib/syntax_tree.rb', line 3787 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
3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 |
# File 'lib/syntax_tree.rb', line 3803 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
3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 |
# File 'lib/syntax_tree.rb', line 3825 def to_json(*opts) { type: :command_call, receiver: receiver, op: operator, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |