From: Guillaume Cottenceau Date: 2001-09-26T07:40:48+09:00 Subject: [ruby-talk:21692] Re: manipulating "immutable" objects such as Fixnum from within callbacks & al... "Lyle Johnson" writes: > > Here's the problem: it happens often that you need to pass "references" to > > objects so that callbacks/functions/etc may modify these objects to their > > convenience, and you will need the modified value afterwards. > > > > Now with "immutable" objects such as Fixnum (also described as objects > > that have "immediate" values by the pickaxe book --> you can't mutate a > > given instance) I can't directly do that... and since "everything" is > > references in Ruby I don't know how to pass a reference to a Fixnum apart > > doing the following, that is an object which is basically a container > > holding one object (o) : > > > > You do understand that because Fixnums are immutable, that the instance that > ObjContainer.o refers to is actually a *different* object after the doit_() > method processes it, right? That is to say, if you were to compare the > object id of ObjContainer.o before and after calling doit_(), you'd get > different ids. Of course. > Assuming you're OK with that, and if the function is really as simple as > your doit_() example, you might as well have doit_() take a Fixnum as input > and return the (new) Fixnum as its result. No, I said that it's a more general problem. I need it to be acting like if I were passing reference. Think if I want to give 3 Fixnum's and 2 Strings to my functions and them all potentially modified, your suggestion would not be ok. And also the function may terminate and keep the references for further modifications (that's why I said "callback"). -- Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/