Methods in Ruby on rails

By: Brian Marick Emailed: 1791 times Printed: 2624 times    

Ruby methods let you create new verbs (messages) in the Ruby lan- methods guage. It’s a bit confusing that two closely related ideas—messages and methods—have such similar names. 

Delimiting Blocks

Blocks can start with a do and end with end, or they can start with { and end with }. The following two snippets of code mean the same thing:

array.each do | element |

puts element

end

array.each { | element |

puts element

}

My sense is that Rubyists prefer the first except for short blocks, especially those that can fit on one line:

array.each { | element | puts element }

Most Viewed Articles (in Ruby )

Latest Articles (in Ruby)

Comment on this tutorial