From: Lyle Johnson Date: 2001-09-26T07:21:17+09:00 Subject: [ruby-talk:21689] Re: manipulating "immutable" objects such as Fixnum from within callbacks & al... > 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. 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.