Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Patterns > Block Local Variables

Block Local Variables

In Ruby’s 1.8 series, local variables introduced in the body of a block are not assigned constant offsets in the local variable array. Ruby’s interpreter keeps a list of these variables and searches the list when accessing such a variable. You can avoid this overhead by changing a block local variable into a method local variable by assigning it some value before entering the block.

For example, change


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial