Programming Tutorials

Methods in Ruby on rails

By: Brian Marick in Ruby Tutorials on 2008-10-17  

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 }






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Ruby )

Latest Articles (in Ruby)