Class: SyntaxTree::BlockArg
Overview
BlockArg represents declaring a block parameter on a method definition.
def method(&block); end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#name ⇒ Object
readonly
- nil | Ident
-
the name of the block argument.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(name:, location:, comments: []) ⇒ BlockArg
constructor
A new instance of BlockArg.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(name:, location:, comments: []) ⇒ BlockArg
Returns a new instance of BlockArg.
2074 2075 2076 2077 2078 |
# File 'lib/syntax_tree/node.rb', line 2074 def initialize(name:, location:, comments: []) @name = name @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2072 2073 2074 |
# File 'lib/syntax_tree/node.rb', line 2072 def comments @comments end |
#name ⇒ Object (readonly)
- nil | Ident
-
the name of the block argument
2069 2070 2071 |
# File 'lib/syntax_tree/node.rb', line 2069 def name @name end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
2080 2081 2082 |
# File 'lib/syntax_tree/node.rb', line 2080 def child_nodes [name] end |
#deconstruct_keys(keys) ⇒ Object
2086 2087 2088 |
# File 'lib/syntax_tree/node.rb', line 2086 def deconstruct_keys(keys) { name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
2090 2091 2092 2093 |
# File 'lib/syntax_tree/node.rb', line 2090 def format(q) q.text("&") q.format(name) if name end |
#pretty_print(q) ⇒ Object
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 |
# File 'lib/syntax_tree/node.rb', line 2095 def pretty_print(q) q.group(2, "(", ")") do q.text("blockarg") if name q.breakable q.pp(name) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2108 2109 2110 2111 2112 |
# File 'lib/syntax_tree/node.rb', line 2108 def to_json(*opts) { type: :blockarg, name: name, loc: location, cmts: comments }.to_json( *opts ) end |