Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

call backs in Ruby

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the Call backs in ruby?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • 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.
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic