New in Ruby 1.9: Block Scoping

By manik March 16, 2008

Ruby 1.9 provides the block scoping of the local variables. It shadows the outside local variable in the block and allocates a new object_id in the memory to the block variable, which essentially means much more flexibility in using the lambdas without worrying about the name of the block variable. Remember that instance, class and global variables are still the same and can be used outside and inside the block as usual.

ruby <= 1.8

ruby 1.9 (shadows the local variable a)

Share this:

Leave a comment

Your email address will not be published. Required fields are marked *