Class: Spicerack::ArrayIndex
- Inherits:
-
Object
- Object
- Spicerack::ArrayIndex
- Includes:
- ShortCircuIt
- Defined in:
- lib/spicerack/array_index.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
Instance Method Summary collapse
- #freeze ⇒ Object
- #index ⇒ Object
-
#initialize(array) ⇒ ArrayIndex
constructor
A new instance of ArrayIndex.
Constructor Details
#initialize(array) ⇒ ArrayIndex
15 16 17 |
# File 'lib/spicerack/array_index.rb', line 15 def initialize(array) @array = array end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
11 12 13 |
# File 'lib/spicerack/array_index.rb', line 11 def array @array end |
Instance Method Details
#freeze ⇒ Object
26 27 28 29 30 31 |
# File 'lib/spicerack/array_index.rb', line 26 def freeze @array = array.deep_dup.freeze index.freeze super end |
#index ⇒ Object
19 20 21 22 23 |
# File 'lib/spicerack/array_index.rb', line 19 def index array.each_with_index.each_with_object({}) do |(element, index), hash| hash[element] = index unless hash.key?(element) end end |