class

PDF::Objects::Array

Inherits Indexable < Enumerable < Iterable < PDF::Objects::Base < Reference < Object

Represents a PDF array object.

PDF arrays are one-dimensional collections of objects enclosed in square brackets. Array elements can be any PDF object type, including other arrays (for multi-dimensional data).

arr = PDF::Objects::Array.new
arr << PDF::Objects::Number.new(1)
arr << PDF::Objects::Number.new(2)
arr << PDF::Objects::Number.new(3)
arr.to_pdf # => "[1 2 3]"

# Or using the convenience initializer
arr = PDF::Objects::Array.new([1, 2, 3])
arr.to_pdf # => "[1 2 3]"

Constructors

new(elements : ::Array(Base))
Source
new(numbers : ::Array(Int32))

Convenience initializer for integer arrays

Source
new(numbers : ::Array(Float64))

Convenience initializer for float arrays

Source

Instance methods

<<(element : Base) : self

Array mutation methods

Source
==(other : self)

Returns true if this reference is the same as other. Invokes same?.

[]=(index : Int, value : Base) : Base
Source
clear
Source
empty?

Returns true if self is empty, false otherwise.

([] of Int32).empty? # => true
([1]).empty?         # => false
Source
hash(hasher)

See Object#hash(hasher)

push(element : Base) : self
Source
size

Indexable implementation

Source
to_pdf(io : IO) : Nil

Serializes this object to an IO.

By default, this writes the result of #to_pdf to the IO. Subclasses may override for more efficient streaming.

Source
to_pdf

Serializes this object to PDF syntax.

Returns the PDF representation as a string.

Source
unsafe_fetch(index : Int) : Base

Returns the element at the given index, without doing any bounds check.

Indexable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they access elements with #[](index) and #[]?(index).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.

Source