Class: SyntaxTree::Yield
- Inherits:
-
Object
- Object
- SyntaxTree::Yield
- Defined in:
- lib/syntax_tree.rb
Overview
Yield represents using the yield keyword with arguments.
yield value
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- Args | Paren
-
the arguments passed to the yield.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(arguments:, location:, comments: []) ⇒ Yield
constructor
A new instance of Yield.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(arguments:, location:, comments: []) ⇒ Yield
Returns a new instance of Yield.
13842 13843 13844 13845 13846 |
# File 'lib/syntax_tree.rb', line 13842 def initialize(arguments:, location:, comments: []) @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args | Paren
-
the arguments passed to the yield
13834 13835 13836 |
# File 'lib/syntax_tree.rb', line 13834 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
13840 13841 13842 |
# File 'lib/syntax_tree.rb', line 13840 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
13837 13838 13839 |
# File 'lib/syntax_tree.rb', line 13837 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
13848 13849 13850 |
# File 'lib/syntax_tree.rb', line 13848 def child_nodes [arguments] end |
#format(q) ⇒ Object
13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 |
# File 'lib/syntax_tree.rb', line 13852 def format(q) q.group do q.text("yield") if arguments.is_a?(Paren) q.format(arguments) else q.if_break { q.text("(") }.if_flat { q.text(" ") } q.indent do q.breakable("") q.format(arguments) end q.breakable("") q.if_break { q.text(")") } end end end |
#pretty_print(q) ⇒ Object
13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 |
# File 'lib/syntax_tree.rb', line 13870 def pretty_print(q) q.group(2, "(", ")") do q.text("yield") q.breakable q.pp(arguments) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
13881 13882 13883 13884 13885 |
# File 'lib/syntax_tree.rb', line 13881 def to_json(*opts) { type: :yield, args: arguments, loc: location, cmts: comments }.to_json( *opts ) end |