Class: Array
- Includes:
- Enumerable
- Defined in:
- lib/kyanite/set.rb,
lib/kyanite/array.rb,
lib/kyanite/dictionary.rb,
lib/kyanite/string/chars.rb,
lib/kyanite/enumerable/structure.rb,
lib/kyanite/enumerable/enumerable_strings.rb,
lib/kyanite/enumerable/enumerable_numerics.rb,
lib/kyanite/enumerable/enumerable_enumerables.rb
Overview
Array Additions
- Kyanite definitions
- Kyanite tests and examples
-
TestKyaniteArray
- Usage
-
require ‘kyanite/array’
Required from Facets Array:
- delete_unless(&block)
-
Inverse of
delete_if - delete_values(*values)
-
Delete multiple values from array (findet und löscht bestimmte Werte)
- delete_values_at(*selectors)
-
Delete multiple values from array given indexes or index range (löscht Elemente an bestimmten Positionen)
- rotate(n=1)
-
Rotates an array’s elements from back to front n times (alles rückt n Positionen auf)
- select!{ |obj| block }
-
As with
selectbut modifies the Array in place. - to_h(arrayed=nil)
-
Converts a two-element associative array into a hash.
Direct Known Subclasses
Cast collapse
-
#to_array_of_enumerables ⇒ ArrayOfEnumerables
Returns ArrayOfEnumerables (this is an Array with modul EnumerableEnumerables included).
-
#to_array_of_numerics ⇒ ArrayOfNumerics
Returns ArrayOfNumerics (this is an Array with modul EnumerableNumerics included).
-
#to_array_of_strings ⇒ ArrayOfStrings
Returns ArrayOfStrings (this is an Array with modul EnumerableStrings included).
-
#to_dictionary ⇒ Dictionary
Returns Dictionary.
-
#to_ordered_set ⇒ OrderedSet
Returns OrderedSet, tests and examples here.
-
#to_sorted_set ⇒ SortedSet
Returns SortedSet, tests and examples here.
Upcase and Downcase with support for special letters like german umlauts collapse
-
#to_s_utf8 ⇒ String
reverse of String#to_array_of_codepoints.
Instance Method Summary collapse
-
#rephrase_index(i, style = :inv) ⇒ Integer
Rephrases the index of an Array pos / neg / inv.
-
#shift_complement ⇒ Object
Cuts the front portion, and returns the rest.
Methods included from Enumerable
#contentclass, #distribution, #is_collection?, #transpose!
Instance Method Details
#rephrase_index(i, style = :inv) ⇒ Integer
Rephrases the index of an Array pos / neg / inv.
- :pos
-
The index is rephrased as a positive integer
- :detect_last
-
The index is rephrased as a positive integer, but the last index is -1
- :neg
-
The index is rephrased as a negative integer
- :inv
-
if it was positive, then it will get negative, and vice versa
See tests and examples here
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/kyanite/array.rb', line 69 def rephrase_index(i, style=:inv) return i if i > (size-1) return i if i < -size case style when :inv if i >=0 # pos >> neg (i - size) else # neg >> pos (i + size) end when :pos if i >= 0 # pos bleibt i else # neg >> pos (i + size) end when :neg if i >= 0 # pos >> neg (i - size) else # neg bleibt i end when :detect_last if i >= 0 # pos bleibt eigentlich if (i == size-1) -1 # nur der Letzte wird -1 genannt else i end else # neg >> pos (i + size) end end #case end |
#shift_complement ⇒ Object
Cuts the front portion, and returns the rest. If the remainder is only one element, it’ not returned as an array but as single element. Useful for recursions. Example:
[1,2,3].shift_complement => [2,3]
[1,2,3].shift_complement.shift_complement => 3
[1,2,3].shift_complement.shift_complement.shift_complement => nil
See tests and examples here.
47 48 49 50 51 52 53 |
# File 'lib/kyanite/array.rb', line 47 def shift_complement if self.size > 2 self[1..-1] else self[-1] end end |
#to_array_of_enumerables ⇒ ArrayOfEnumerables
Returns ArrayOfEnumerables (this is an Array with modul EnumerableEnumerables included)
61 62 63 |
# File 'lib/kyanite/enumerable/enumerable_enumerables.rb', line 61 def to_array_of_enumerables ArrayOfEnumerables.new(self) end |
#to_array_of_numerics ⇒ ArrayOfNumerics
Returns ArrayOfNumerics (this is an Array with modul EnumerableNumerics included)
137 138 139 |
# File 'lib/kyanite/enumerable/enumerable_numerics.rb', line 137 def to_array_of_numerics ArrayOfNumerics.new(self) end |
#to_array_of_strings ⇒ ArrayOfStrings
Returns ArrayOfStrings (this is an Array with modul EnumerableStrings included)
50 51 52 |
# File 'lib/kyanite/enumerable/enumerable_strings.rb', line 50 def to_array_of_strings ArrayOfStrings.new(self) end |
#to_dictionary ⇒ Dictionary
Returns Dictionary
77 78 79 80 81 82 83 84 |
# File 'lib/kyanite/dictionary.rb', line 77 def to_dictionary # TODO: effizienter result = Dictionary.new self.each do | zeile | result << zeile end result end |
#to_ordered_set ⇒ OrderedSet
Returns OrderedSet, tests and examples here.
184 185 186 |
# File 'lib/kyanite/set.rb', line 184 def to_ordered_set OrderedSet.new(self) end |
#to_s_utf8 ⇒ String
reverse of String#to_array_of_codepoints
248 249 250 |
# File 'lib/kyanite/string/chars.rb', line 248 def to_s_utf8 self.pack("U*").encode('utf-8') end |