class HexaPDF::PDFArray

Included Modules

Implementation of the PDF array type.

This is mainly done to provide automatic resolution of indirect object references when using the [] method. Therefore not all Array methods are implemented - use the value directly if other methods are needed.

See: PDF1.7 s7.3.6

Public Instance Methods


Append a value to the array.

array[index] → obj or nil
array[start, length] → new_array or nil
array[range] → new_array or nil

Returns the value at the given index, or a subarray using the given start and length, or a subarray specified by range.

This method should be used instead of direct access to a value because it provides some advantages:

  • References are automatically resolved.

  • Returns the native Ruby object for values with class HexaPDF::Object. However, all subclasses of HexaPDF::Object are returned as is (it makes no sense, for example, to return the hash that describes the Catalog instead of the Catalog object).

[]=(index, data)

Stores the data under the given index in the array.

If the current value for this index has the class HexaPDF::Object (and only this, no subclasses) and the given data has not (including subclasses), the data is stored inside the HexaPDF::Object.


Deletes the value at the given index.

each {|value| block} → array
each → Enumerator

Calls the given block once for every value of the array.

Note that the yielded value is already preprocessed like in [].


Returns true if the array has no elements.

index(obj) → int or nil
index {|item| block } → int or nil
index → Enumerator

Returns the index of the first object such that object is == to obj, or, if a block is given, the index of the first object for which the block returns true.

insert(index, *objects)

Insert one or more values into the array at the given index.


Returns the number of elements in the array.

Also aliased as: size
reject! {|item| block } → array or nil
reject! → Enumerator

Deletes all elements from the array for which the block returns true. If no changes were done, returns nil.

Alias for: length
slice!(index) → obj or nil
slice!(start, length) → new_array or nil
slice!(range) → new_array or nil

Deletes the element(s) given by an index (and optionally a length) or by a range, and returns them or nil if the index is out of range.


Returns a duplicate of the underlying array.


Returns the values at the given indices.

See [] for details