How is a block like a function?

The way that I see a block as a function is because both can be call and you can pas parameters to both.

How is a block different from a function?

One of the major differences that I see is that you can pass a block to a block but you can not pass a function to a function.

What are the two ways to declare a block?

The Ruby standard is to use braces for single-line blocks and do..end for multi-line blocks.

How do you return data from a block?

Ruby blocks will return the last line by default, so make sure that you put on the last line what you want to return.

What happens if you include a return statement in a block?

It will return that line instead of the last line

Why would you use a block instead of just creating a method?

Because blocks can be pass to other blocks and to other methods, and methods no

What does yield do?

Will pause the method and execute the code on the block, after that it will return to the method

How do you pass arguments to a block from within a method?

putting the parameters that you want to pass between pipes.




Copyright 2017. All rights reserved.

Posted December 12, 2016 by Edmundo in category "Daily