class Prism::Pack::Format - Documentation for Ruby 4.0
Description: class Prism::Pack::Format: The result of parsing a pack template.
Keywords: ruby,class,Prism::Pack::Format

🔍

No recent searches

# class Prism::Pack::Format

The result of parsing a pack template.

### Attributes

directives [R]

A list of the directives in the template.

encoding [R]

The encoding of the template.

### Public Class Methods

new (directives, encoding)
Source

    # File lib/prism/pack.rb, line 208
    def initialize(directives, encoding)
      @directives = directives
      @encoding = encoding
    end

Create a new `Format` with the given directives and encoding.

### Public Instance Methods

describe ()
Source

    # File lib/prism/pack.rb, line 214
    def describe
      source_width = directives.map { |d| d.source.inspect.length }.max
      directive_lines = directives.map do |directive|
        if directive.type == SPACE
          source = directive.source.inspect
        else
          source = directive.source
        end
        # @type var source_width: Integer
        "  #{source.ljust(source_width)}  #{directive.describe}"
      end

      (["Directives:"] + directive_lines + ["Encoding:", "  #{encoding}"]).join("\n")
    end

Provide a human-readable description of the format.