Class: ActiveRecord::Result::IndexedRow
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activerecord/lib/active_record/result.rb |
Class Method Summary
- .new(column_indexes, row) ⇒ IndexedRow constructor
Instance Method Summary
- #==(other)
- #[](column)
- #each_key(&block)
- #fetch(column)
- #key?(column) ⇒ Boolean
- #keys
-
#length
Alias for #size.
- #size (also: #length)
- #to_h (also: #to_hash)
-
#to_hash
Alias for #to_h.
Constructor Details
.new(column_indexes, row) ⇒ IndexedRow
# File 'activerecord/lib/active_record/result.rb', line 40
def initialize(column_indexes, row) @column_indexes = column_indexes @row = row end
Instance Method Details
#==(other)
[ GitHub ]#[](column)
[ GitHub ]# File 'activerecord/lib/active_record/result.rb', line 80
def [](column) if index = @column_indexes[column] @row[index] end end
#each_key(&block)
[ GitHub ]# File 'activerecord/lib/active_record/result.rb', line 50
def each_key(&block) @column_indexes.each_key(&block) end
#fetch(column)
[ GitHub ]# File 'activerecord/lib/active_record/result.rb', line 70
def fetch(column) if index = @column_indexes[column] @row[index] elsif block_given? yield else raise KeyError, "key not found: #{column.inspect}" end end
#key?(column) ⇒ Boolean
# File 'activerecord/lib/active_record/result.rb', line 66
def key?(column) @column_indexes.key?(column) end
#keys
[ GitHub ]# File 'activerecord/lib/active_record/result.rb', line 54
def keys @column_indexes.keys end
#length
Alias for #size.
# File 'activerecord/lib/active_record/result.rb', line 48
alias_method :length, :size
#size Also known as: #length
[ GitHub ]# File 'activerecord/lib/active_record/result.rb', line 45
def size @column_indexes.size end
#to_h Also known as: #to_hash
[ GitHub ]# File 'activerecord/lib/active_record/result.rb', line 86
def to_h @column_indexes.transform_values { |index| @row[index] } end
#to_hash
Alias for #to_h.