Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/einutricional/menu_dietetico.rb
Instance Method Summary collapse
Instance Method Details
#sort_each ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/einutricional/menu_dietetico.rb', line 128 def sort_each final = [] final << shift each do |i| final_index = 0 while final_index < final.length if i <= final[final_index] final.insert(final_index, i) break elsif final_index == final.length - 1 final.insert(final_index + 1, i) break end final_index += 1 end end final end |
#sort_for ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/einutricional/menu_dietetico.rb', line 109 def sort_for final = [] final << shift for i in self final_index = 0 while final_index < final.length if i <= final[final_index] final.insert(final_index, i) break elsif final_index == final.length - 1 final.insert(final_index + 1, i) break end final_index += 1 end end final end |
#sorted? ⇒ Boolean
105 106 107 |
# File 'lib/einutricional/menu_dietetico.rb', line 105 def sorted? each_cons(2).all? {|left, right| left <= right} end |