Nuttig Iterators en Methoden voor Ruby on Rails

Als u wilt reizen door de items in een database die u hebt gemaakt met Ruby on Rails, het kennen van de iterators te gebruiken is de sleutel. De volgende tabel toont behulpzaam iteratoren en methoden:

[1, 2, 3] .each {} => [1, 2, 3]
[1 nihil nihil, 2, 3, nil] .compact {} => [1, 2, 3]
[1, 2, 3] .delete_if {| x | x> = 3} => [1, 2]
[1, 2, 3] .collect {| x | x + 1} => [2, 3, 4]
[1, 2, 3] .find_all {| x | x% 2 == 1} => [1, 3]
[1, 2, 3] .reject {| x | x% 2 == 1} => [2]
[2, 5, 1, 0, 7] .sort => [0, 1, 2, 5, 7]
[2, 5, 1, 0, 7] .max => 7
[1 [2, 3]]. Flatten => [1, 2, 3]
[1, 2, 3] .empty? => False
[] .empty? => True
[0, 5, 9] gunstiger prijs, krijg => 3
[1, 2, 3] .include? (2) => True
[1, 2, 3] .include? (16) => False
[1, 2, 3] .reverse => [3, 2, 1]