Using Code Blocks question


#1

So I'm on 11. Usinc Code Blocks and the explination is doing my head in a bit.

Per the explanation:

A method can take a block as a parameter. That's what .each has been doing this whole time: taking a block as a parameter and doing stuff with it! You just didn't notice because we didn't use the optional parentheses.

And then you have the code:

[1, 2, 3, 4, 5].each { |i| puts i }

So given that methods are defined and could contain arguments, with the above code and as far as blocks are concerned is the array [1, 2, 3, 4, 5] the definition and the .each the argument? I get that blocks are pretty much undefined methods, but the "taking a block as a parameter" is confusing me.

Anyone care to explain?


#2

Hey. I'm new in here too but i think i got this right, if not I'm sorry maybe somebody smarter will correct me, but here's my explanation for this.

.each { |i| puts i }

here is the methods itself as this is a block of code wich is like a tool. You can put new things in it every time it won't go into waste after a time. Not a bunch of code that runs one time and vanish. I think the parameter here is the array itself as it is the coin wich runs trough the machine.
i mean you could use infinite number of different arrays and you could stil use this very code like.
[3,6, 7, 5].each { |i| puts i }
or
[1, 5, 1].each { |i| puts i }