Class: Prism::Merge::Comment::Block
- Inherits:
-
Ast::Merge::Comment::Block
- Object
- Ast::Merge::Comment::Block
- Prism::Merge::Comment::Block
- Defined in:
- lib/prism/merge/comment/block.rb
Overview
Ruby-specific comment block with magic comment detection.
Extends the generic Ast::Merge::Comment::Block with Ruby-specific
features like detection and enumeration of magic comments.
Instance Method Summary collapse
-
#contains_magic_comment? ⇒ Boolean
(also: #magic_comment?)
Check if this block contains a magic comment.
-
#initialize(children:) ⇒ Block
constructor
Initialize a new Ruby comment Block.
-
#inspect ⇒ String
Human-readable representation.
-
#magic_comments ⇒ Array<Line>
Get all magic comments in this block.
-
#signature ⇒ Array
Generate signature for matching.
Constructor Details
#initialize(children:) ⇒ Block
Initialize a new Ruby comment Block.
23 24 25 |
# File 'lib/prism/merge/comment/block.rb', line 23 def initialize(children:) super(children: children, style: :hash_comment) end |
Instance Method Details
#contains_magic_comment? ⇒ Boolean Also known as: magic_comment?
Check if this block contains a magic comment.
30 31 32 |
# File 'lib/prism/merge/comment/block.rb', line 30 def contains_magic_comment? children.any? { |c| c.is_a?(Line) && c.magic_comment? } end |
#inspect ⇒ String
Returns Human-readable representation.
63 64 65 66 |
# File 'lib/prism/merge/comment/block.rb', line 63 def inspect magic = contains_magic_comment? ? ' has_magic_comments' : '' "#<Prism::Merge::Comment::Block lines=#{location.start_line}..#{location.end_line}#{magic} children=#{children.size}>" end |
#magic_comments ⇒ Array<Line>
Get all magic comments in this block.
40 41 42 |
# File 'lib/prism/merge/comment/block.rb', line 40 def magic_comments children.select { |c| c.is_a?(Line) && c.magic_comment? } end |
#signature ⇒ Array
Generate signature for matching.
For blocks containing magic comments, uses the FIRST magic comment's signature (by type) so that blocks with the same type of magic comment will match regardless of value (e.g., true vs false).
For non-magic blocks, uses the parent implementation.
53 54 55 56 57 58 59 60 |
# File 'lib/prism/merge/comment/block.rb', line 53 def signature if contains_magic_comment? # Use the first magic comment's signature magic_comments.first.signature else super end end |