Geert, This has come up in different varations before, but the answer is always "No, ruby doesn't support that and most likely never will.". Primarily, this is because such a "feature" is considered by most (myself included) to be a mis-feature. Such a thing would mean that ruby's behavior in many places would be drasticly different to support this, an really there is no reason. If you believe that you MUST have such a think to solve a problem, it's probably time to step out of that box you are in (if you glance back at it as you do, you'll see that someone has written "C" on the side of the box as well). Given that, what problem do you believe that you need such a feature to convey nicely? In the 3-4 years since I started using ruby, I haven't yet come up with one myself. If you have some, I'm sure the community would help you work through the "ruby way" to solve it. - Evan Phoenix <evan / fallingsnow.net> On 3/9/06, Geert Fannes <Geert.Fannes / ikanconsulting.com> wrote: > Hello, > > > > One thing that hinders the usability of Ruby for the things I want to > do, is the fact that certain objects cannot be modified "in place" and > always return NEW objects (like Fixnum, Bignum or Float), making it hard > to do parameter passing by reference or similar things. Things get > easily out of sync and both memory and cpu time (and programming > overhead) has to be wasted to keep things going as should. > > > > To make things clear: Suppose I have a certain number distributed over > different objects and I want this number to be synchronized (read "the > same") in these different places: > > > > a=b=12 #a and b are my to objects I want to be synchronized > > a+=1 > > p a #=> 13 > > p b #=> 12 KO :-( I want it to be 13, exactly the same as a > > > > I can of course capture this number in a class, and distribute the class > object instead of the number object: > > > > class Bla > > attr :number,true > > end > > (a=b=Bla.new).number=12 > > a.number+=1 > > p a.number #=> 13 > > p b.number #=> 13 OK! :-) > > > > But now my code looks more complicated, I have an extra class and have > to remember to use the instance variable .number. This also wastes too > much memory when e.g. implementing a matrix object where I want to have > both an array holding the rows, one for holding the columns and the > actual rows and columns SHARE the same numbers using objects of type > Bla. This way, if I modify a certain element (say element at row i, > column j) by taking the i-th row and modifying the j-th element in that > row, I want to see the change also if I access the same matrix element > by selecting the j-th column and the i-th element from that column. > > > > I tried to create a class that contains a certain Ruby object and that > passes all the incoming methods to the contained object, acting as a > kind of reference. > > > > class Reference > > attr :containedObject,true > > > > def initialize(obj) > > @containedObject=obj > > end > > > > #handle missing methods and pass them to the contained object > > def method_missing(methodSymbol,*args) > > @containedObject.send(methodSymbol,*args) > > end > > > > #override some general existing methods, to make sure that a Reference > object is as stealth as possible > > def class > > @containedObject.class > > end > > #unfortunately, this fails since assignment cannot be overloaded, > which makes sense, but still ... > > def =(rhs) > > @containedObject=rhs > > end > > end > > > > Unfortunately, I cannot overload the assignment operator (and some other > operators), so I still cannot work with these objects as if I was > working with a normal number. So my guess is that to implement such a > Reference class, I have to go deeper and dive in the Ruby code itself, > modifying the unoverloadable operators in the parser etc. > > > > This seems a bit drastic, if someone knows an easier solution to this > problem, please let me know. If not, are there people willing to help me > with introducing a Reference object in Ruby or have suggestions how this > can be done? I cannot imagine no one encountered the same problems > before. > > > > Greetings, > > Geert. > > > -- When I do good, I feel good; when I do bad, I feel bad, and that is my religion. -- Abraham Lincoln (1809 - 1865)