>>>>> "GC" == Guillaume Cottenceau <gc / mandrakesoft.com> writes:
GC> Well it's more generic than that. See my answer to Lyle. I
GC> want to use, say, "callbacks" with many parameters and let the
GC> "callbacks" manipulate the "values" as they want but still be
GC> able to access to new values from outside of the "callbacks".
Well, I'd recommend either just using arrays as object holders, i.e.
def doit(lst)
lst[0] += 1
end
l = [1]
doit(l) ->2
l[0] ->2
or simply defining a callback class that manages all of the state you
need, like
class Callback
def initialize(val) @val = val; end
attr_accessor :val
def doit() @val += 1; end
end
k = Callback.new 5
k.doit
k.val
i.e. make the "callback function" a method of the class, unlike your
first example.
Hope that helps,
--Johann