Ruby accessing outer variables in nested function Ruby accessing outer variables in nested function ruby ruby

Ruby accessing outer variables in nested function


As far as I know, defining a named function within a function does not give you access to any local variables.

What you can do instead is use a Proc:

def foo(x)  bar = lambda do    puts x  end  bar.call  42endfoo(5)