Search code examples
rubyvariablessyntaxblock

What does the |variable| syntax mean?


What is the | | around profile below called, what does it mean, and why it is after do? I thought do is followed by a loop block or so.

ticks = get_all[0...MAX].map do |profile|
  # ...
end

Solution

  • it's like a foreach, so profile will be a different value in each of the functions calls, one function call per element in get_all.

    see this:

    my_array = [:uno, :dos, :tres]
    my_array.each do |item| 
        puts item
    end