On Dec 7, 2:19 am, Vasyl Smirnov <vasyl.smir... / gmail.com> wrote:
> Hi,
>
> I wonder if there is any way to create local variables dynamically,
> for example, given
>
> def foo
>   bar
>   puts x, y
> end
>
> is it possible for bar to somehow create and initialize x and y?
> Binding doesn't seem to be modifiable..
>
> Or am I asking too much? :)

There are probably more clever ways than this, but I'm dumb...

def bar
  x = 10
  y = 20
  binding
end

def foo
  eval("puts x, y", bar)
end

Regards,
Jordan