Local Variable Scope in Ruby and How to Get Around It

Part of Screencast Series: Ruby Metaprogramming Revealed

Published October 2015

Scoping out your local variables

Any serious Ruby developer has to understand what the scope is and how relates to variables. However, did you know that local variables can actually be smuggled between scopes easily using metaprogramming tricks? This video explain how to achieve this! You’ll also learn how to execute arbitrary code in the context of an object and the differences between instance_eval and instance_exec.


Have your say! or become a member now to take part in the discussion

Meet your instructor
Ilya Bodrov-Krukowski

Ilya is a lecturer at MATI-RSTU, senior engineer at Campaigner LLC and seasoned author at SitePoint. When Ilya is not working away on new projects or contributing to open source projects, he's expanding and refining his skills in HTML, CSS, jQuery, Angular, Backbone and Rails. You can read all about his work and development discoveries on his blog Radiant Wind.