Class: RubyMVC::Models::KeyedArrayTableModel::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_mvc/models/keyed_array_table_model.rb

Overview

This class provides a row adapter for each row in the array so that it behaves effectively like a Hash instance, but which still allows the underlying array to be manipulated without problem.

Instance Method Summary collapse

Constructor Details

#initialize(keys, row) ⇒ Row

The instance is created with an array of strings or symbols used to denote the keys of the model. The keys MUST be specified in the order of the data elements in the data array. When the model is asked for the value for a given key, the value is retrieved from the data array by the position of the key in the keys array.



44
45
46
47
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 44

def initialize(keys, row)
  @keys = keys
  @row = row
end

Instance Method Details

#[](key) ⇒ Object



49
50
51
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 49

def [](key)
  @row[@keys[key.to_sym]]
end

#[]=(key, val) ⇒ Object



53
54
55
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 53

def []=(key, val)
  @row[@keys[key.to_sym]] = val
end