Module: Array::Hooked::ArrayInterface

Extended by:
Module::Cluster
Includes:
IdentifiesAs
Included in:
Array::Hooked
Defined in:
lib/array/hooked/array_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configuration_instanceObject

configuration_instance #



86
87
88
# File 'lib/array/hooked/array_interface.rb', line 86

def configuration_instance
  @configuration_instance
end

Instance Method Details

#-(*arrays) ⇒ Object

  • #



347
348
349
350
351
352
353
354
355
# File 'lib/array/hooked/array_interface.rb', line 347

def -( *arrays )

  arrays.each do |this_array|
    delete_objects( *this_array )
  end

  return self

end

#[](index) ⇒ Object

#



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/array/hooked/array_interface.rb', line 182

def []( index )

  object = nil
  
  should_get = true
  
  unless @without_hooks
    should_get = pre_get_hook( index )
  end
  
  if should_get
    
    object = super( index )
  
    unless @without_hooks
      object = post_get_hook( index, object )
    end
    
  end
  
  return object
  
end

#[]=(index, object) ⇒ Object Also known as: hooked_set

[]= #

hooked_set  #


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/array/hooked/array_interface.rb', line 211

def []=( index, object )

  # we are either replacing or adding at the end
  # if we are replacing we are either replacing a parent element or an element in self
  # * if replacing parent element, track and exclude parent changes

  unless @without_hooks
    object = pre_set_hook( index, object, false )
  end
  
  perform_set_between_hooks( index, object )

  unless @without_hooks
    object = post_set_hook( index, object, false )
  end

  return object

end

#clearObject

clear #



769
770
771
772
773
774
775
# File 'lib/array/hooked/array_interface.rb', line 769

def clear

  delete_if { true }

  return self

end

#clear_without_hooksObject

Alias to :clear that bypasses hooks.

Returns:

  • (Object)

    Self.



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'lib/array/hooked/array_interface.rb', line 1303

def clear_without_hooks

  @without_hooks = true

  clear
  
  @without_hooks = false
  
  return self
  
end

#collect!Object Also known as: map!

collect! #

map!      #


610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/array/hooked/array_interface.rb', line 610

def collect!

  return to_enum unless block_given?

  self.each_with_index do |this_object, index|
    replacement_object = yield( this_object )
    self[ index ] = replacement_object
  end

  return self

end

#collect_without_hooks! { ... } ⇒ Object Also known as: map_without_hooks!

Alias to :select that bypasses hooks.

Yields:

  • Block passed to :collect!.

Returns:

  • (Object)

    Self.



1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
# File 'lib/array/hooked/array_interface.rb', line 1152

def collect_without_hooks!( & block )
  
  @without_hooks = true

  collect!( & block )
  
  @without_hooks = false
  
  return self
  
end

#compact!Object

compact! #



451
452
453
454
455
456
457
# File 'lib/array/hooked/array_interface.rb', line 451

def compact!

  return keep_if do |object|
    object != nil
  end

end

#compact_without_hooks!Object

Alias to :compact that bypasses hooks.

Returns:

  • (Object)

    Self.



1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'lib/array/hooked/array_interface.rb', line 1001

def compact_without_hooks!

  @without_hooks = true

  compact!
  
  @without_hooks = false

  return self

end

#concat(*arrays) ⇒ Object Also known as: +

concat #



279
280
281
282
283
284
285
286
287
# File 'lib/array/hooked/array_interface.rb', line 279

def concat( *arrays )

  arrays.each do |this_array|
    push( *this_array )
  end

  return self

end

#concat_without_hooks(*arrays) ⇒ Object

Alias to :concat that bypasses hooks.

Parameters:

  • objects (Array<Object>)

    Elements being concatenated.

Returns:

  • (Object)

    Element returned.



869
870
871
872
873
874
875
876
877
878
879
# File 'lib/array/hooked/array_interface.rb', line 869

def concat_without_hooks( *arrays )

  @without_hooks = true

  concat( *arrays )
  
  @without_hooks = false

  return arrays

end

#delete(object) ⇒ Object Also known as: hooked_delete

delete #

hooked_delete  #


296
297
298
299
300
301
302
303
304
305
306
# File 'lib/array/hooked/array_interface.rb', line 296

def delete( object )

  return_value = nil

  if index = index( object )
    return_value = delete_at( index )
  end

  return return_value

end

#delete_at(index) ⇒ Object Also known as: hooked_delete_at

delete_at #



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/array/hooked/array_interface.rb', line 361

def delete_at( index )

  deleted_object = nil

  if @without_hooks
    pre_delete_hook_result = true
  else
    pre_delete_hook_result = pre_delete_hook( index )
  end
  
  if pre_delete_hook_result
    
    deleted_object = perform_delete_at_between_hooks( index )

    unless @without_hooks
      deleted_object = post_delete_hook( index, deleted_object )
    end

  end

  return deleted_object

end

#delete_at_indexes(*indexes) ⇒ Object

delete_at_indexes #



391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/array/hooked/array_interface.rb', line 391

def delete_at_indexes( *indexes )

  indexes = indexes.sort.uniq.reverse

  objects = [ ]

  indexes.each do |this_index|
    objects.push( delete_at( this_index ) )
  end

  return objects

end

#delete_at_indexes_without_hooks(*indexes) ⇒ Object

Alias to :delete_at that bypasses hooks and takes multiple indexes.

Parameters:

  • index (Array<Fixnum>)

    Index to delete.

Returns:

  • (Object)

    Deleted element.



945
946
947
948
949
950
951
952
953
954
955
# File 'lib/array/hooked/array_interface.rb', line 945

def delete_at_indexes_without_hooks( *indexes )
  
  @without_hooks = true

  objects = delete_at_indexes( *indexes )
  
  @without_hooks = false

  return objects
  
end

#delete_at_without_hooks(index) ⇒ Object

Alias to :delete_at that bypasses hooks.

Parameters:

  • index (Fixnum)

    Index to delete.

Returns:

  • (Object)

    Deleted element.



926
927
928
929
930
931
932
933
934
935
936
# File 'lib/array/hooked/array_interface.rb', line 926

def delete_at_without_hooks( index )

  @without_hooks = true

  object = delete_at( index )
  
  @without_hooks = false

  return object
  
end

#delete_ifObject

delete_if #



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/array/hooked/array_interface.rb', line 409

def delete_if

  return to_enum unless block_given?

  indexes = [ ]

  self.each_with_index do |this_object, index|
    if yield( this_object )
      indexes.push( index )
    end
  end

  delete_at_indexes( *indexes )

  return self

end

#delete_if_without_hooks { ... } ⇒ Object

Alias to :delete_if that bypasses hooks.

Yields:

  • Block passed to :delete_if.

Returns:

  • (Object)

    Deleted element.



964
965
966
967
968
969
970
971
972
973
974
# File 'lib/array/hooked/array_interface.rb', line 964

def delete_if_without_hooks( & block )

  @without_hooks = true

  delete_if( & block )
  
  @without_hooks = false

  return self

end

#delete_objects(object, ...) ⇒ Array<Object>

Delete more than one object at a time.

Parameters:

  • object

    Object to delete.

Returns:

  • (Array<Object>)

    Deleted objects.



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/array/hooked/array_interface.rb', line 323

def delete_objects( *objects )

  return_value = nil

  indexes = [ ]
  objects.each do |this_object|
    this_index = index( this_object )
    if this_index
      indexes.push( this_index )
    end
  end

  unless indexes.empty?
    return_value = delete_at_indexes( *indexes )
  end

  return return_value

end

#delete_objects_without_hooks(*objects) ⇒ Object

Alias to :delete that bypasses hooks and takes multiple objects.

Parameters:

  • objects (Array<Object>)

    Elements being deleted.

Returns:

  • (Object)

    Element returned.



907
908
909
910
911
912
913
914
915
916
917
# File 'lib/array/hooked/array_interface.rb', line 907

def delete_objects_without_hooks( *objects )

  @without_hooks = true

  return_value = delete_objects( *objects )
  
  @without_hooks = false

  return return_value

end

#delete_without_hooks(object) ⇒ Object

Alias to :delete that bypasses hooks.

Parameters:

  • object (Object)

    Element being deleted.

Returns:

  • (Object)

    Element returned.



888
889
890
891
892
893
894
895
896
897
898
# File 'lib/array/hooked/array_interface.rb', line 888

def delete_without_hooks( object )

  @without_hooks = true

  return_value = delete( object )
  
  @without_hooks = false

  return return_value

end

#flatten!Object

flatten! #



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/array/hooked/array_interface.rb', line 463

def flatten!

  return_value = nil

  indexes = [ ]

  self.each_with_index do |this_object, this_index|
    if this_object.is_a?( ::Array )
      indexes.push( this_index )
    end
  end

  unless indexes.empty?
    indexes.sort!.reverse!
    indexes.each do |this_index|
      this_array = delete_at( this_index )
      insert( this_index, *this_array )
    end
    return_value = self
  end

  return return_value

end

#flatten_without_hooks!Object

Alias to :flatten that bypasses hooks.

Returns:

  • (Object)

    Self.



1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/array/hooked/array_interface.rb', line 1019

def flatten_without_hooks!

  @without_hooks = true

  return_value = flatten!
  
  @without_hooks = false

  return return_value

end

#get_without_hooks(index) ⇒ Object

Alias to :[] that bypasses hooks.

Parameters:

  • index (Fixnum)

    Index at which set is taking place.

Returns:

  • (Object)

    Element returned.



786
787
788
789
790
791
792
793
794
795
796
# File 'lib/array/hooked/array_interface.rb', line 786

def get_without_hooks( index )
  
  @without_hooks = true

  self[ index ] = object
  
  @without_hooks = false
  
  return object
  
end

#initialize(configuration_instance = nil, *args) ⇒ true, false

Initialize with reference a configuration instance.

Parameters:

  • object (Object)

    Object that HookedArray instance is attached to, primarily useful for reference from hooks.

  • args (Array<Object>)

    Parameters passed through super to Array#initialize.

Returns:

  • (true, false)

    Whether receiver identifies as object.



74
75
76
77
78
79
80
# File 'lib/array/hooked/array_interface.rb', line 74

def initialize( configuration_instance = nil, *args )
  
  @configuration_instance = configuration_instance

  super( *args )
      
end

#insert(index, *objects) ⇒ Object Also known as: hooked_insert

insert #

hooked_insert  #


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/array/hooked/array_interface.rb', line 238

def insert( index, *objects )

  index = filter_insert_objects( index, objects )

  unless @without_hooks
    objects.each_with_index do |this_object, this_index|
      this_object = pre_set_hook( index + this_index, this_object, true )
      objects[ this_index ] = this_object
    end
  end

  perform_insert_between_hooks( index, *objects )

  unless @without_hooks
    objects.each_with_index do |this_object, this_index|
      objects[ this_index ] = post_set_hook( index + this_index, this_object, true )
    end
  end
      
  return objects

end

#insert_without_hooks(index, *objects) ⇒ Object

Alias to :insert that bypasses hooks.

Parameters:

  • index (Fixnum)

    Index at which set is taking place.

  • objects (Array<Object>)

    Elements being inserted.

Returns:

  • (Object)

    Element returned.



831
832
833
834
835
836
837
838
839
840
841
# File 'lib/array/hooked/array_interface.rb', line 831

def insert_without_hooks( index, *objects )

  @without_hooks = true

  super( index, *objects )
  
  @without_hooks = false

  return objects

end

#keep_ifObject

keep_if #



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/array/hooked/array_interface.rb', line 431

def keep_if

  indexes = [ ]

  self.each_with_index do |this_object, index|
    unless yield( this_object )
      indexes.push( index )
    end
  end

  delete_at_indexes( *indexes )

  return self

end

#keep_if_without_hooks { ... } ⇒ Object

Alias to :keep_if that bypasses hooks.

Yields:

  • Block passed to :keep_if.

Returns:

  • (Object)

    Deleted element.



983
984
985
986
987
988
989
990
991
992
993
# File 'lib/array/hooked/array_interface.rb', line 983

def keep_if_without_hooks( & block )

  @without_hooks = true

  keep_if( & block )
  
  @without_hooks = false

  return self

end

#popObject

pop #



701
702
703
704
705
706
707
# File 'lib/array/hooked/array_interface.rb', line 701

def pop

  object = delete_at( count - 1 )

  return object

end

#pop_without_hooksObject

Alias to :pop that bypasses hooks.

Returns:

  • (Object)

    Self.



1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
# File 'lib/array/hooked/array_interface.rb', line 1247

def pop_without_hooks

  @without_hooks = true

  object = pop
  
  @without_hooks = false

  return object

end

#post_delete_hook(index, object) ⇒ Object

A hook that is called after deleting a value.

Parameters:

  • index (Fixnum)

    Index at which delete took place.

  • object (Object)

    Element deleted.

Returns:

  • (Object)

    Object returned in place of delete result.



170
171
172
173
174
# File 'lib/array/hooked/array_interface.rb', line 170

def post_delete_hook( index, object )
  
  return object
  
end

#post_get_hook(index, object) ⇒ Object

A hook that is called after getting a value.

Parameters:

  • index (Fixnum)

    Index at which get is taking place.

  • object (Object)

    Element being set/inserted.

Returns:

  • (Object)

    Object returned in place of get result.



142
143
144
145
146
# File 'lib/array/hooked/array_interface.rb', line 142

def post_get_hook( index, object )
  
  return object
  
end

#post_set_hook(index, object, is_insert = false) ⇒ Object

A hook that is called after setting a value.

Parameters:

  • index (Fixnum)

    Index at which set/insert is taking place.

  • object (Object)

    Element being set/inserted.

  • is_insert (true, false) (defaults to: false)

    Whether this set is inserting a new index.

Returns:

  • (Object)

    Ignored.



114
115
116
117
118
# File 'lib/array/hooked/array_interface.rb', line 114

def post_set_hook( index, object, is_insert = false )
  
  return object
  
end

#pre_delete_hook(index) ⇒ true, false

A hook that is called before deleting a value; if return value is false, delete does not occur.

Parameters:

  • index (Fixnum)

    Index at which delete is taking place.

Returns:

  • (true, false)

    If return value is false, delete does not occur.



155
156
157
158
159
160
# File 'lib/array/hooked/array_interface.rb', line 155

def pre_delete_hook( index )
  
  # false means delete does not take place
  return true
  
end

#pre_get_hook(index) ⇒ true, false

A hook that is called before getting a value; if return value is false, get does not occur.

Parameters:

  • index (Fixnum)

    Index at which set/insert is taking place.

Returns:

  • (true, false)

    If return value is false, get does not occur.



127
128
129
130
131
132
# File 'lib/array/hooked/array_interface.rb', line 127

def pre_get_hook( index )
  
  # false means get does not take place
  return true
  
end

#pre_set_hook(index, object, is_insert = false) ⇒ true, false

A hook that is called before setting a value; return value is used in place of object.

Parameters:

  • index (Fixnum)

    Index at which set/insert is taking place.

  • object (Object)

    Element being set/inserted.

  • is_insert (true, false) (defaults to: false)

    Whether this set is inserting a new index.

Returns:

  • (true, false)

    Return value is used in place of object.



99
100
101
102
103
# File 'lib/array/hooked/array_interface.rb', line 99

def pre_set_hook( index, object, is_insert = false )

  return object
  
end

#push(*objects) ⇒ Object Also known as: <<

push #



267
268
269
270
271
# File 'lib/array/hooked/array_interface.rb', line 267

def push( *objects )

  return insert( count, *objects )

end

#push_without_hooks(*objects) ⇒ Object

Alias to :push that bypasses hooks.

Parameters:

  • objects (Array<Object>)

    Elements being pushed.

Returns:

  • (Object)

    Element returned.



850
851
852
853
854
855
856
857
858
859
860
# File 'lib/array/hooked/array_interface.rb', line 850

def push_without_hooks( *objects )

  @without_hooks = true

  push( *objects )
  
  @without_hooks = false

  return objects

end

#reject!Object

reject! #



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/array/hooked/array_interface.rb', line 492

def reject!

  return to_enum unless block_given?

  return_value = nil

  deleted_objects = 0

  iteration_dup = dup
  iteration_dup.each_with_index do |this_object, index|
    if yield( this_object )
      delete_at( index - deleted_objects )
      deleted_objects += 1
    end
  end

  if deleted_objects > 0
    return_value = self
  end

  return return_value

end

#reject_without_hooks! { ... } ⇒ Object

Alias to :reject that bypasses hooks.

Yields:

  • Block passed to :keep_if.

Returns:

  • (Object)

    Self.



1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
# File 'lib/array/hooked/array_interface.rb', line 1038

def reject_without_hooks!( & block )

  @without_hooks = true

  reject!( & block )
  
  @without_hooks = false

  return return_value

end

#replace(other_array) ⇒ Object

replace #



520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/array/hooked/array_interface.rb', line 520

def replace( other_array )

  clear

  other_array.each_with_index do |this_object, index|
    unless self[ index ] == this_object
      self[ index ] = this_object
    end
  end

  return self

end

#replace_without_hooks(other_array) ⇒ Object

Alias to :replace that bypasses hooks.

Parameters:

  • other_array (Array)

    Other array to replace self with.

Returns:

  • (Object)

    Self.



1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
# File 'lib/array/hooked/array_interface.rb', line 1057

def replace_without_hooks( other_array )
  
  @without_hooks = true

  replace( other_array )
  
  @without_hooks = false
  
  return self
  
end

#reverse!Object

reverse! #



538
539
540
541
542
543
544
545
546
# File 'lib/array/hooked/array_interface.rb', line 538

def reverse!

  reversed_array = reverse

  replace( reversed_array )

  return self

end

#reverse_without_hooks!Object

Alias to :reverse that bypasses hooks.

Returns:

  • (Object)

    Self.



1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
# File 'lib/array/hooked/array_interface.rb', line 1075

def reverse_without_hooks!

  @without_hooks = true

  reverse!
  
  @without_hooks = false

  return self

end

#rotate!(rotate_count = 1) ⇒ Object

rotate! #



552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/array/hooked/array_interface.rb', line 552

def rotate!( rotate_count = 1 )

  reversed_array = rotate( rotate_count )

  clear

  reversed_array.each_with_index do |this_object, index|
    self[ index ] = this_object
  end

  return self

end

#rotate_without_hooks!(rotate_count = 1) ⇒ Object

Alias to :rotate that bypasses hooks.

Parameters:

  • rotate_count (Fixnum) (defaults to: 1)

    Integer count of how many elements to rotate.

Returns:

  • (Object)

    Self.



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
# File 'lib/array/hooked/array_interface.rb', line 1094

def rotate_without_hooks!( rotate_count = 1 )

  @without_hooks = true

  rotate!( rotate_count )
  
  @without_hooks = false

  return self

end

#select!Object

select! #



570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/array/hooked/array_interface.rb', line 570

def select!

  return to_enum unless block_given?

  deleted_objects = 0

  dup.each_with_index do |this_object, index|
    unless yield( this_object )
      delete_at( index - deleted_objects )
      deleted_objects += 1
    end
  end

  return self

end

#select_without_hooks! { ... } ⇒ Object

Alias to :select that bypasses hooks.

Yields:

  • Block passed to :select!.

Returns:

  • (Object)

    Self.



1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
# File 'lib/array/hooked/array_interface.rb', line 1113

def select_without_hooks!( & block )

  @without_hooks = true

  select!( & block )
  
  @without_hooks = false

  return self

end

#set_without_hooks(index, object) ⇒ Object

Alias to :[]= that bypasses hooks.

Parameters:

  • index (Fixnum)

    Index at which set is taking place.

  • object (Object)

    Element being set.

Returns:

  • (Object)

    Element returned.



806
807
808
809
810
811
812
813
814
815
816
# File 'lib/array/hooked/array_interface.rb', line 806

def set_without_hooks( index, object )
  
  @without_hooks = true

  self[ index ] = object
  
  @without_hooks = false
  
  return object
  
end

#shiftObject

shift #



713
714
715
716
717
718
719
# File 'lib/array/hooked/array_interface.rb', line 713

def shift

  object = delete_at( 0 )

  return object

end

#shift_without_hooksObject

Alias to :shift that bypasses hooks.

Returns:

  • (Object)

    Self.



1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
# File 'lib/array/hooked/array_interface.rb', line 1265

def shift_without_hooks

  @without_hooks = true

  object = shift
  
  @without_hooks = false
  
  return object
  
end

#shuffle!(random_number_generator = nil) ⇒ Object

shuffle! #



591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/array/hooked/array_interface.rb', line 591

def shuffle!( random_number_generator = nil )

  shuffled_array = shuffle( random: random_number_generator )

  clear

  shuffled_array.each_with_index do |this_object, index|
    self[ index ] = this_object
  end

  return self

end

#shuffle_without_hooks!(random_number_generator = nil) ⇒ Object

Alias to :shuffle that bypasses hooks.

Parameters:

  • random_number_generator (Object) (defaults to: nil)

    Random number generator passed to :shuffle!.

Returns:

  • (Object)

    Self.



1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File 'lib/array/hooked/array_interface.rb', line 1132

def shuffle_without_hooks!( random_number_generator = nil )

  @without_hooks = true

  shuffle!( random_number_generator )
  
  @without_hooks = false

  return self

end

#slice!(index_start_or_range, length = nil) ⇒ Object

slice! #



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'lib/array/hooked/array_interface.rb', line 725

def slice!( index_start_or_range, length = nil )

  slice = nil

  start_index = nil
  end_index = nil

  if index_start_or_range.is_a?( Range )

    start_index = index_start_or_range.begin
    end_index = index_start_or_range.end

  elsif length

    start_index = index_start_or_range
    end_index = index_start_or_range + length

  end

  if end_index

    indexes = [ ]

    ( end_index - start_index ).times do |this_time|
      indexes.push( end_index - this_time - 1 )
    end

    slice = delete_at_indexes( *indexes )

  else

    slice = delete_at( start_index )

  end


  return slice

end

#slice_without_hooks!(index_start_or_range, length = nil) ⇒ Object

Alias to :slice! that bypasses hooks.

Parameters:

  • index_start_or_range (Fixnum)

    Index at which to begin slice.

  • length (Fixnum) (defaults to: nil)

    Length of slice.

Returns:

  • (Object)

    Self.



1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
# File 'lib/array/hooked/array_interface.rb', line 1285

def slice_without_hooks!( index_start_or_range, length = nil )

  @without_hooks = true

  slice = slice!( index_start_or_range, length )
  
  @without_hooks = false
  
  return slice
  
end

#sort!(&block) ⇒ Object

sort! #



629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/array/hooked/array_interface.rb', line 629

def sort!( & block )

  sorted_array = sort( & block )

  unless sorted_array == self

    replace( sorted_array )

  end

  return self

end

#sort_by!(&block) ⇒ Object

sort_by! #



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/array/hooked/array_interface.rb', line 647

def sort_by!( & block )

  return to_enum unless block_given?

  sorted_array = sort_by( & block )

  unless sorted_array == self

    replace( sorted_array )

  end

  return self

end

#sort_by_without_hooks! { ... } ⇒ Object

Alias to :sort_by! that bypasses hooks.

Yields:

  • Block passed to :sort_by!.

Returns:

  • (Object)

    Self.



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/array/hooked/array_interface.rb', line 1192

def sort_by_without_hooks!( & block )
  
  @without_hooks = true

  sort_by!( & block )
  
  @without_hooks = false
  
  return self
  
end

#sort_without_hooks! { ... } ⇒ Object

Alias to :sort that bypasses hooks.

Yields:

  • Block passed to :sort!.

Returns:

  • (Object)

    Self.



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/array/hooked/array_interface.rb', line 1173

def sort_without_hooks!( & block )
  
  @without_hooks = true

  sort!
  
  @without_hooks = false
  
  return self
  
end

#uniq!Object

uniq! #



667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/array/hooked/array_interface.rb', line 667

def uniq!

  return_value = nil

  uniq_array = uniq

  unless self == uniq_array

    clear
    
    replace( uniq_array )

  end

  return return_value

end

#uniq_without_hooks!Object

Alias to :uniq! that bypasses hooks.

Returns:

  • (Object)

    Self.



1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
# File 'lib/array/hooked/array_interface.rb', line 1210

def uniq_without_hooks!

  @without_hooks = true

  return_value = uniq!
  
  @without_hooks = false

  return return_value

end

#unshift(object) ⇒ Object

unshift #



689
690
691
692
693
694
695
# File 'lib/array/hooked/array_interface.rb', line 689

def unshift( object )

  insert( 0, object )

  return self

end

#unshift_without_hooks(object) ⇒ Object

Alias to :unshift that bypasses hooks.

Parameters:

  • object (Object)

    Object to unshift onto self.

Returns:

  • (Object)

    Self.



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'lib/array/hooked/array_interface.rb', line 1229

def unshift_without_hooks( object )

  @without_hooks = true

  unshift( object )
  
  @without_hooks = false
  
  return self
  
end