# frozen_string_literal: true # This file is part of PacketGen # See https://github.com/sdaubert/packetgen for more informations # Copyright (C) 2016 Sylvain Daubert # This program is published under MIT license. require 'forwardable' module PacketGen module Types # @abstract Base class to define set of {Fields} subclasses. # == #record_from_hash # Subclasses should define private method +#record_from_hash+. This method # is called by {#push} to add an object to the set. # # A default method is defined by {Array}: it calls constructor of class defined # by {.set_of}. # # == #real_type # Subclasses should define private method +#real_type+ if {.set_of} type # may be subclassed. This method should return real class to use. It # takes an only argument, which is of type given by {.set_of}. # # Default behaviour of this method is to return argument's class. # # @author Sylvain Daubert class Array extend Forwardable include Enumerable include Fieldable include LengthFrom # @!method [](index) # Return the element at +index+. # @param [integer] index # @return [Object] # @!method clear # Clear array. # @return [void] # @!method each # Calls the given block once for each element in self, passing that # element as a parameter. Returns the array itself. # @return [Array] # @method empty? # Return +true+ if contains no element. # @return [Booelan] # @!method first # Return first element # @return [Object] # @!method last # Return last element. # @return [Object] # @!method size # Get number of element in array # @return [Integer] def_delegators :@array, :[], :clear, :each, :empty?, :first, :last, :size alias length size # Separator used in {#to_human}. # May be ovverriden by subclasses HUMAN_SEPARATOR = ',' # rubocop:disable Naming/AccessorMethodName class <