Class: Ast::Merge::Comment::Empty

Inherits:
AstNode
  • Object
show all
Defined in:
lib/ast/merge/comment/empty.rb

Overview

Represents an empty/blank line in source code.

Empty lines are important for preserving document structure and separating comment blocks. They serve as natural boundaries between logical sections of comments.

Examples:

empty = Empty.new(line_number: 5)
empty.slice #=> ""
empty.signature #=> [:empty_line]

With whitespace-only content

empty = Empty.new(line_number: 5, text: "   ")
empty.slice #=> "   "
empty.signature #=> [:empty_line]

Instance Attribute Summary collapse

Attributes inherited from AstNode

#location, #slice

Instance Method Summary collapse

Methods inherited from AstNode

#children, #respond_to_missing?, #to_s, #unwrap

Constructor Details

#initialize(line_number:, text: "") ⇒ Empty

Initialize a new Empty line.

Parameters:

  • line_number (Integer)

    The 1-based line number

  • text (String) (defaults to: "")

    The actual line content (may have whitespace)



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ast/merge/comment/empty.rb', line 35

def initialize(line_number:, text: "")
  @line_number = line_number
  @text = text.to_s

  location = AstNode::Location.new(
    start_line: line_number,
    end_line: line_number,
    start_column: 0,
    end_column: @text.length,
  )

  super(slice: @text, location: location)
end

Instance Attribute Details

#line_numberInteger (readonly)

Returns The line number in source.

Returns:

  • (Integer)

    The line number in source



26
27
28
# File 'lib/ast/merge/comment/empty.rb', line 26

def line_number
  @line_number
end

#textString (readonly)

Returns The actual line content (may have whitespace).

Returns:

  • (String)

    The actual line content (may have whitespace)



29
30
31
# File 'lib/ast/merge/comment/empty.rb', line 29

def text
  @text
end

Instance Method Details

#freeze_marker?(_freeze_token) ⇒ Boolean

Empty lines never contain freeze markers.

Parameters:

  • _freeze_token (String)

    Ignored

Returns:

  • (Boolean)

    Always false



67
68
69
# File 'lib/ast/merge/comment/empty.rb', line 67

def freeze_marker?(_freeze_token)
  false
end

#inspectString

Returns Human-readable representation.

Returns:

  • (String)

    Human-readable representation



72
73
74
# File 'lib/ast/merge/comment/empty.rb', line 72

def inspect
  "#<Comment::Empty line=#{line_number}>"
end

#normalized_contentString

Returns Empty normalized content.

Returns:

  • (String)

    Empty normalized content



59
60
61
# File 'lib/ast/merge/comment/empty.rb', line 59

def normalized_content
  ""
end

#signatureArray

Empty lines have a generic signature - they don’t match by content.

All empty lines are considered equivalent for matching purposes.

Returns:

  • (Array)

    Signature for matching



54
55
56
# File 'lib/ast/merge/comment/empty.rb', line 54

def signature
  [:empty_line]
end