Module: Array::Sorted::ArrayInterface
- Includes:
- Hooked::ArrayInterface
- Included in:
- Array::Sorted
- Defined in:
- lib/array/sorted/array_interface.rb
Instance Method Summary collapse
-
#collect! ⇒ Object
(also: #map!)
collect! # map! #.
-
#initialize(configuration_instance = nil, *args) {|object| ... } ⇒ Object
Adds optional block for object by which sort order is determined.
-
#reverse! ⇒ Object
reverse! #.
-
#sort!(&block) ⇒ Object
sort! #.
-
#sort_by!(&block) ⇒ Object
sort_by! #.
Instance Method Details
#collect! ⇒ Object Also known as: map!
collect! #
map! #
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/array/sorted/array_interface.rb', line 60 def collect! return to_enum unless block_given? replacement_array = [ ] self.each_with_index do |this_object, index| replacement_object = yield( this_object ) replacement_array[ index ] = replacement_object end replace( replacement_array ) return self end |
#initialize(configuration_instance = nil, *args) {|object| ... } ⇒ Object
Adds optional block for object by which sort order is determined.
19 20 21 22 23 24 25 26 27 |
# File 'lib/array/sorted/array_interface.rb', line 19 def initialize( configuration_instance = nil, *args, & sort_object_block ) super( configuration_instance, *args ) if block_given? @sort_object_block = sort_object_block end end |
#reverse! ⇒ Object
reverse! #
45 46 47 48 49 50 51 52 53 |
# File 'lib/array/sorted/array_interface.rb', line 45 def reverse! @sort_order_reversed = ! @sort_order_reversed super return self end |
#sort!(&block) ⇒ Object
sort! #
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/array/sorted/array_interface.rb', line 81 def sort!( & block ) if block_given? self.each_with_index do |this_member, index| unless index + 1 == count sort_object = @sort_object_block ? @sort_object_block.call( this_member ) : this_member yield( sort_object, self[ index + 1 ] ) end end end return self end |
#sort_by!(&block) ⇒ Object
sort_by! #
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/array/sorted/array_interface.rb', line 100 def sort_by!( & block ) if block_given? @sort_object_block = block else return to_enum unless block_given? end self.each do |this_member| @sort_object_block.call( this_member ) end return self end |