Sha256: b81e1609eaa6c69e7c55a322781a1e0250fa074be9eadf0905e81624b1ea3e11

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

class Array
  # Assert that the elements in the Array are of the given types
  #
  # @param types [*Class] list of Classes to match against the elements
  # @return [true] if all elements are of the proper type
  # @return [false] otherwise
  # @raise ArgumentError if the number of arguments does not match the length of the Array
  # @raise ArgumentError if an element does not match the require type in the arguments
  def assert_types(*types)
    if types.length != self.length
      raise ArgumentError, "Number of arguments must match length of Array"
    end

    each_index do |i|
      unless self[i].is_a?(types[i])
        raise ArgumentError, "Value at index %s expected to be a %s"%[i, types[i]]
      end
    end

    true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dionysus-2.2.0.0.pre1 lib/dionysus/array/assert_types.rb