flat_map

enum.flat_map { |obj| block } â array
enum.flat_map â an_enumerator
Instance Public methods

Returns a new array with the concatenated results of running block once for every element in enum.

If no block is given, an enumerator is returned instead.

1
2
[1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4]
[[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100]
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.