Is it possible, to pass local variables by refrerence to method?
I would like to do something like that:
def meth(dest)
=C2=A0dest =3D 0 if some_condition
end
...
local_var =3D 1
# some_condition evaluates to true
meth(local_var)
local_var =3D=3D 0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# should eval=
uate to true
There is no way to do exactly that in Ruby. If you pass the name of
the local variable as a string, and pass the binding, you can
accomplish something very similar, e.g.:
def meth(target, context)
result =3D context.eval target
context.eval "#{target} =3D 0"
result
end
local_var =3D 1
meth("local_var",binding) # =3D> 1
local_var =3D=3D 0 # =3D> true
---
But this is ugly in many ways. There are better ways of doing
out-of-band (e.g., other than the return value) communications back to
the caller from a method, like taking a callback function as an
argument and passing data to the callback function. You'll probably
get better feedback on the best way to achieve what you want in Ruby
if you are more specific as to the real goal.