Class: ActiveRecord::Result::IndexedRow
- Inherits:
-
Object
- Object
- ActiveRecord::Result::IndexedRow
- Defined in:
- lib/active_record/result.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](column) ⇒ Object
- #each_key(&block) ⇒ Object
- #fetch(column) ⇒ Object
-
#initialize(column_indexes, row) ⇒ IndexedRow
constructor
A new instance of IndexedRow.
- #key?(column) ⇒ Boolean
- #keys ⇒ Object
- #size ⇒ Object (also: #length)
- #to_h ⇒ Object (also: #to_hash)
Constructor Details
#initialize(column_indexes, row) ⇒ IndexedRow
Returns a new instance of IndexedRow.
40 41 42 43 |
# File 'lib/active_record/result.rb', line 40 def initialize(column_indexes, row) @column_indexes = column_indexes @row = row end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/active_record/result.rb', line 58 def ==(other) if other.is_a?(Hash) to_hash == other else super end end |
#[](column) ⇒ Object
80 81 82 83 84 |
# File 'lib/active_record/result.rb', line 80 def [](column) if index = @column_indexes[column] @row[index] end end |
#each_key(&block) ⇒ Object
50 51 52 |
# File 'lib/active_record/result.rb', line 50 def each_key(&block) @column_indexes.each_key(&block) end |
#fetch(column) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File '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
66 67 68 |
# File 'lib/active_record/result.rb', line 66 def key?(column) @column_indexes.key?(column) end |
#keys ⇒ Object
54 55 56 |
# File 'lib/active_record/result.rb', line 54 def keys @column_indexes.keys end |
#size ⇒ Object Also known as: length
45 46 47 |
# File 'lib/active_record/result.rb', line 45 def size @column_indexes.size end |
#to_h ⇒ Object Also known as: to_hash
86 87 88 |
# File 'lib/active_record/result.rb', line 86 def to_h @column_indexes.transform_values { |index| @row[index] } end |