e x p r e s s i c a

ruby on rails, business and technicalities

No public Twitter messages.

  • RSS
  • Facebook
  • Twitter
  • Linkedin

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

a = 9
p a # => 9
[1, 2, 3].each{|a|}
p a # => 3

ruby 1.9 (shadows the local variable a)

a = 9
p a # => 9
[1, 2, 3].each{|a|}
p a # => 9

Sponsors