Class: GunDog::IndexedArray
- Inherits:
-
Array
- Object
- Array
- GunDog::IndexedArray
- Defined in:
- lib/gun_dog/indexed_array.rb
Instance Attribute Summary collapse
-
#lut ⇒ Object
readonly
Returns the value of attribute lut.
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #find_object(obj) ⇒ Object
- #index_of_object(obj) ⇒ Object
-
#initialize(*args) ⇒ IndexedArray
constructor
A new instance of IndexedArray.
Constructor Details
#initialize(*args) ⇒ IndexedArray
Returns a new instance of IndexedArray.
5 6 7 8 |
# File 'lib/gun_dog/indexed_array.rb', line 5 def initialize(*args) super(args) @lut = {} end |
Instance Attribute Details
#lut ⇒ Object (readonly)
Returns the value of attribute lut.
3 4 5 |
# File 'lib/gun_dog/indexed_array.rb', line 3 def lut @lut end |
Instance Method Details
#<<(obj) ⇒ Object
10 11 12 13 14 |
# File 'lib/gun_dog/indexed_array.rb', line 10 def <<(obj) super(obj) @lut[obj.object_id] = length obj end |
#find_object(obj) ⇒ Object
20 21 22 |
# File 'lib/gun_dog/indexed_array.rb', line 20 def find_object(obj) at(index_of_object(obj)) end |
#index_of_object(obj) ⇒ Object
16 17 18 |
# File 'lib/gun_dog/indexed_array.rb', line 16 def index_of_object(obj) @lut.fetch(obj.object_id) end |