Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call backs in Ruby

 
Suganya Ram
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the Call backs in ruby?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is usually a really difficult concept to grasp the first time.

You know how you can pass parameter objects to a method or constructor call in Java?

Well in Ruby you can also pass a very special kind of object as a parameter called a block or closure. It doesn't look like a normal object, its simply a set of curly braces containing some code.

3.times{
// do something in this block
}

Here the times method is being called and is being passed a single block parameter (remember, the curly braces). It might be easier to visualize this if the syntax looked like:
3.times({ /* some code here */ })
because we're used to always seeing parameters inside of paranthesis.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic