Class: SyntaxTree::Command
- Inherits:
-
Object
- Object
- SyntaxTree::Command
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#message ⇒ Object
readonly
- Const | Ident
-
the message being sent to the implicit receiver.
Instance Method Summary collapse
- #child_nodes ⇒ 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.
3810 3811 3812 3813 3814 3815 |
# File 'lib/syntax_tree.rb', line 3810 def initialize(message:, arguments:, location:, comments: []) @message = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args
-
the arguments being sent with the message
3802 3803 3804 |
# File 'lib/syntax_tree.rb', line 3802 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3808 3809 3810 |
# File 'lib/syntax_tree.rb', line 3808 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3805 3806 3807 |
# File 'lib/syntax_tree.rb', line 3805 def location @location end |
#message ⇒ Object (readonly)
- Const | Ident
-
the message being sent to the implicit receiver
3799 3800 3801 |
# File 'lib/syntax_tree.rb', line 3799 def @message end |
Instance Method Details
#child_nodes ⇒ Object
3817 3818 3819 |
# File 'lib/syntax_tree.rb', line 3817 def child_nodes [, arguments] end |
#format(q) ⇒ Object
3821 3822 3823 3824 3825 3826 3827 |
# File 'lib/syntax_tree.rb', line 3821 def format(q) q.group do q.format() q.text(" ") q.nest(.value.length + 1) { q.format(arguments) } end end |
#pretty_print(q) ⇒ Object
3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 |
# File 'lib/syntax_tree.rb', line 3829 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
3843 3844 3845 3846 3847 3848 3849 3850 3851 |
# File 'lib/syntax_tree.rb', line 3843 def to_json(*opts) { type: :command, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |