Module: Array::Unique::ArrayInterface
- Includes:
- Hooked::ArrayInterface
- Included in:
- Array::Unique
- Defined in:
- lib/array/unique/array_interface.rb
Instance Method Summary collapse
-
#[]=(index, object) ⇒ Object
[]= #.
-
#collect! ⇒ Object
(also: #map!)
collect! # map! #.
-
#include?(object) ⇒ Boolean
include? #.
-
#initialize(configuration_instance = nil, *args) ⇒ Object
initialize #.
-
#perform_delete_at_between_hooks(index) ⇒ Object
perform_delete_at_between_hooks #.
-
#perform_single_object_insert_between_hooks(index, object) ⇒ Object
perform_single_object_insert_between_hooks #.
-
#uniq ⇒ Object
uniq #.
-
#uniq! ⇒ Object
uniq! #.
Instance Method Details
#[]=(index, object) ⇒ Object
[]= #
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/array/unique/array_interface.rb', line 26 def []=( index, object ) # we only set if we don't already have the object being inserted # for this reason we return nil if no insert occurred return_value = nil # make sure that set is unique unless @unique_keys.has_key?( object ) if index > count index = count unless object.nil? or @unique_keys.has_key?( nil ) index += 1 end end return_value = super @unique_keys[ object ] = true end return return_value end |
#collect! ⇒ Object Also known as: map!
collect! #
map! #
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/array/unique/array_interface.rb', line 96 def collect! return to_enum unless block_given? delete_indexes = [ ] self.each_with_index do |this_object, index| replacement_object = yield( this_object ) if @unique_keys.has_key?( replacement_object ) and replacement_object != this_object delete_indexes.push( index ) else self[ index ] = replacement_object end end delete_indexes.sort.reverse.each do |this_index| delete_at( this_index ) end return self end |
#include?(object) ⇒ Boolean
include? #
85 86 87 88 89 |
# File 'lib/array/unique/array_interface.rb', line 85 def include?( object ) return @unique_keys.has_key?( object ) end |
#initialize(configuration_instance = nil, *args) ⇒ Object
initialize #
12 13 14 15 16 17 18 |
# File 'lib/array/unique/array_interface.rb', line 12 def initialize( configuration_instance = nil, *args ) @unique_keys = { } super end |
#perform_delete_at_between_hooks(index) ⇒ Object
perform_delete_at_between_hooks #
73 74 75 76 77 78 79 |
# File 'lib/array/unique/array_interface.rb', line 73 def perform_delete_at_between_hooks( index ) @unique_keys.delete( self[ index ] ) return super end |
#perform_single_object_insert_between_hooks(index, object) ⇒ Object
perform_single_object_insert_between_hooks #
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/array/unique/array_interface.rb', line 56 def perform_single_object_insert_between_hooks( index, object ) if @unique_keys.has_key?( object ) index = nil else @unique_keys[ object ] = true index = super end return index end |
#uniq ⇒ Object
uniq #
123 124 125 126 127 |
# File 'lib/array/unique/array_interface.rb', line 123 def uniq return self end |
#uniq! ⇒ Object
uniq! #
133 134 135 136 137 |
# File 'lib/array/unique/array_interface.rb', line 133 def uniq! return self end |