background preloader

Ruby-Related Sites

Facebook Twitter

Shrink your URLs and get paid! Ruby on Rails Application Development And Consulting Company. Activerecord. Rails. Web Programming. Rubyonrails. “AkitaOnRails” On Anatomy of Ruby Blocks/Closures. Fabio Akita’s “AkitaOnRails” series at RubyLearning.com, for would-be Ruby developers, has been quite a hit. Today in another article, Fabio talks in depth about Ruby’s Blocks/Closures, This is a rather long article but well worth the time invested in reading it. The entire source code for the programs in this article is available here.

Fabio Akita is a Brazilian Rails enthusiast, also known online as “AkitaOnRails”. He regularly write posts on his own blog and had published the very first book tailored for the Brazilian audience called “Repensando a Web com Rails”. Note: You may want to brush up on Ruby Blocks and Procs before going through Fabio’s article. Fabio>> There is no Rubyism more difficult to explain, than a Closure. Let’s start with an example: # program1.rb for i in [1,2,3,4] puts i end a = 0 b = [1,2,3,4] while a < b.length puts b[a] a += 1 end These are very simple iterators, similar to what we have in several languages. This is not valid Ruby code, of course. Ruby Programming - Defined?, And, Or, and Not. A Ruby Learning Hub.