wood burning stoves 2.0*
The moose likes Ruby and the fly likes call backs in Ruby Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Languages » Ruby
Bookmark "call backs in Ruby" Watch "call backs in Ruby" New topic
Author

call backs in Ruby

Suganya Ram
Greenhorn

Joined: Jun 12, 2008
Posts: 18
What are the Call backs in ruby?


SuganyaRam
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: call backs in Ruby