Skip to Content Skip to Search
Methods
#
F
I
L
N
S

Class Public methods

[](hash)

Builds a Mutable row from a Hash, indexed in the Hash’s order. : (Hash[String, untyped] | Mutable) -> Mutable

# File activemodel/lib/active_model/indexed_row.rb, line 359
def self.[](hash)
  return hash if hash.is_a?(self)

  new(IndexedRow.build_indexes(hash.keys).freeze, hash.values)
end

new(indexes, row = nil, size: indexes.size)

: (Hash[String, Integer] | ExtendedIndexes, ?Array?, ?size: Integer) -> void

# File activemodel/lib/active_model/indexed_row.rb, line 366
def initialize(indexes, row = nil, size: indexes.size)
  @indexes = indexes
  @row = row || IndexedRow.unset_row(size)
end

Instance Public methods

[]=(column, value)

Columns that aren’t in the indexes are added after the last index. The indexes are replaced rather than modified, since they’re usually shared with other rows. : (String, untyped) -> untyped

# File activemodel/lib/active_model/indexed_row.rb, line 392
def []=(column, value)
  unless index = @indexes[column]
    index = [@row.size, IndexedRow.max_slot(@indexes) + 1].max
    @indexes = ExtendedIndexes.add(@indexes, column, index)
  end

  if index >= @row.size
    @row.concat(IndexedRow.unset_row(index - @row.size + 1))
  end

  @row[index] = value
end

freeze()

: () -> self

# File activemodel/lib/active_model/indexed_row.rb, line 378
def freeze
  @row.freeze
  super
end

initialize_copy(other)

: (Mutable) -> void

# File activemodel/lib/active_model/indexed_row.rb, line 372
def initialize_copy(other)
  super
  @row = @row.dup
end

length()

Alias for: size

size()

Also aliased as: length
# File activemodel/lib/active_model/indexed_row.rb, line 383
def size
  @row.size - @row.count(UNSET)
end