From: "Thomas B." Date: 2008-09-06T18:24:03+09:00 Subject: Re: Request: arguments by reference Pedro Silva wrote: > Would be possible to include the option to pass arguments by reference > instead of by value? I think not. In Java you cannot pass by reference, and that's not because Java is a poor language where things cannot be done easily. That's because Java enforces other way of programming than, say C. It's Object Oriented programming, namely. Passing by reference is adding mess. The = sign after a variable name assigns a new value to this variable, and let this be that way. Similarly += and the family. If you need badly the variables to really change values, do what should be done in an object oriented language: wrap them in classes, and add accessors. That's the way you'd also do it in Java. > The actual way forces the programmer to > know if any particular method creates or not a new object. In fact, programming forces the programmer to know how to programme. And knowing what creates a new object and what not, is part of this knowledge. And in Ruby it's not very hard to guess. > Taking into account that Ruby uses > mainly references for each object (fixnum and company are the > exceptions) (...) In fact Ruby always passes the reference to an object by value, no matter if it is Fixnum or whatever. The only difference is that Fixnums (and some others) are immutable, so they simply do not have methods like << that change their values in-place. Ruby behaves the same way with any class of arguments, it's the class itself that does or does not allow an in-place change. TPR. -- Posted via http://www.ruby-forum.com/.