ruby - Using do block vs brackets {} -


Enter your newbie glove, new to Ruby.

Is there any difference (unclear or practical) between the following two snippets?

  my_array = [: uno,: dos,: tres] my_array.each {| Items | The item adds my_array = [: uno,: dos ,: tres] my_array.each do | Items | The end of the item  

I know that bracket syntax will allow you to put the block on one line

  my_array.each {| Item | }  

But there are no compelling reasons to use a syntax on the other outside of it?

says that do..end

in the bracket syntax

has more priority sequence, keep in mind that there is a high priority of Bracket syntax, consider the following two snippets of code compared to Do..end syntax:

  1.upto 3 do X | Puts x termination 1.upto 3 {| X | On the other hand only works when parentheses are used,  1.upto (3) {| X | Puts x}  


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -