Class: Furud::ArrayValue

Inherits:
Data
  • Object
show all
Defined in:
lib/furud/types.rb,
sig/furud.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows:) ⇒ ArrayValue

Returns a new instance of ArrayValue.

Parameters:

  • rows: (Array[Array[untyped]])

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
# File 'lib/furud/types.rb', line 58

def initialize(rows:)
  rows = rows.map { |row| row.dup.freeze }.freeze
  raise ArgumentError, "array must not be empty" if rows.empty? || rows.any?(&:empty?)
  raise ArgumentError, "array rows must have equal length" unless rows.map(&:length).uniq.one?

  super(rows: rows)
end

Instance Attribute Details

#rows ⇒ Object (readonly)

Returns the value of attribute rows

Returns:

  • (Object) —

    the current value of rows



57
58
59
# File 'lib/furud/types.rb', line 57

def rows
  @rows
end

Instance Method Details

#[](row, column) ⇒ Object

Parameters:

  • row (Integer)
  • column (Integer)

Returns:

  • (Object)


68
# File 'lib/furud/types.rb', line 68

def [](row, column) = rows[row][column]

#height ⇒ Integer

Returns:

  • (Integer)


66
# File 'lib/furud/types.rb', line 66

def height = rows.length

#width ⇒ Integer

Returns:

  • (Integer)


67
# File 'lib/furud/types.rb', line 67

def width = rows.first.length