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
Returns a new instance of ArrayIndex.
19 20 21 22 23 24 25 |
# File 'lib/spicerack/array_index.rb', line 19 def initialize(*array) if array.length == 1 && array[0].respond_to?(:to_ary) @array = array[0].to_a else @array = array end end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
14 15 16 |
# File 'lib/spicerack/array_index.rb', line 14 def array @array end |
Instance Method Details
#freeze ⇒ Object
34 35 36 37 38 39 |
# File 'lib/spicerack/array_index.rb', line 34 def freeze @array = _deep_freeze_and_dup_object(array).freeze index.freeze super end |
#index ⇒ Object
27 28 29 30 31 |
# File 'lib/spicerack/array_index.rb', line 27 def index array.each_with_index.each_with_object({}) do |(element, index), hash| hash[element] = index unless hash.key?(element) end end |