It's not a secret anymore!
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
JavaRanch » Java Forums » Languages » Ruby
Bookmark "call backs in Ruby" Watch "call backs in Ruby" New topic

call backs in Ruby

Suganya Ram

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

Marc Peabody
pie sneak

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.

// 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:
subject: call backs in Ruby
It's not a secret anymore!