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.
3689 3690 3691 3692 3693 3694 |
# File 'lib/syntax_tree.rb', line 3689 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
3681 3682 3683 |
# File 'lib/syntax_tree.rb', line 3681 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3687 3688 3689 |
# File 'lib/syntax_tree.rb', line 3687 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3684 3685 3686 |
# File 'lib/syntax_tree.rb', line 3684 def location @location end |
#message ⇒ Object (readonly)
- Const | Ident
-
the message being sent to the implicit receiver
3678 3679 3680 |
# File 'lib/syntax_tree.rb', line 3678 def @message end |
Instance Method Details
#child_nodes ⇒ Object
3696 3697 3698 |
# File 'lib/syntax_tree.rb', line 3696 def child_nodes [, arguments] end |
#format(q) ⇒ Object
3700 3701 3702 3703 3704 3705 3706 |
# File 'lib/syntax_tree.rb', line 3700 def format(q) q.group do q.format() q.text(" ") q.nest(.value.length + 1) { q.format(arguments) } end end |
#pretty_print(q) ⇒ Object
3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 |
# File 'lib/syntax_tree.rb', line 3708 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
3722 3723 3724 3725 3726 3727 3728 3729 3730 |
# File 'lib/syntax_tree.rb', line 3722 def to_json(*opts) { type: :command, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |