Class: ActiveModel::IndexedRow
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Inherits: | Object |
| Defined in: | activemodel/lib/active_model/indexed_row.rb |
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #==(other)
- #[](column)
- #each_key(&block)
- #eql?(other) ⇒ Boolean
- #fetch(column)
- #hash
- #key?(column) ⇒ Boolean
- #keys
-
#length
Alias for #size.
- #new_empty_mutable_row
- #size (also: #length)
- #to_h (also: #to_hash)
-
#to_hash
Alias for #to_h.
- #values
- #values_at(*columns)
Constructor Details
.new(indexes, row) ⇒ IndexedRow
Class Method Details
.[](hash)
[ GitHub ].build_indexes(columns)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 16
def build_indexes(columns) index = -1 columns.index_with { index += 1 } end
Instance Attribute Details
#indexes (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 22
attr_reader :indexes, :row
#row (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 22
attr_reader :indexes, :row
Instance Method Details
#==(other)
[ GitHub ]#[](column)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 87
def [](column) if index = @indexes[column] @row[index] end end
#each_key(&block)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 34
def each_key(&block) @indexes.each_key(&block) end
#eql?(other) ⇒ Boolean
#fetch(column)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 77
def fetch(column) if index = @indexes[column] @row[index] elsif block_given? yield else raise KeyError, "key not found: #{column.inspect}" end end
#hash
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 63
def hash [IndexedRow, @indexes, @row].hash end
#key?(column) ⇒ Boolean
# File 'activemodel/lib/active_model/indexed_row.rb', line 73
def key?(column) @indexes.key?(column) end
#keys
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 38
def keys @indexes.keys end
#length
Alias for #size.
# File 'activemodel/lib/active_model/indexed_row.rb', line 32
alias_method :length, :size
#new_empty_mutable_row
[ GitHub ]#size Also known as: #length
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 29
def size @indexes.size end
#to_h Also known as: #to_hash
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 93
def to_h @indexes.transform_values { |index| @row[index] } end
#to_hash
Alias for #to_h.
#values
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 42
def values @row.dup end
#values_at(*columns)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 46
def values_at(*columns) columns.map! do |column| if index = @indexes[column] @row[index] end end columns end