From: Robert Klemme Date: 2008-09-08T20:06:06+09:00 Subject: Re: Request: arguments by reference 2008/9/6 Pedro Silva : > Would be possible to include the option to pass arguments by reference > instead of by value? Maybe. > I know the above example can be done like 'a, b = b, a', but this always > obliges to set things directly and never allow to use functions, that, > in my opinion, is a limitation. Did it ever occur to you that others might actually consider this a liberation? If you introduce call by reference the way you suggest you cannot be sure that the instance you assigned to a variable is still the same after method calls. This can lead to subtle bugs. > The actual way forces the programmer to > know if any particular method creates or not a new object. Regardless of language features the user of a function or method (or class for that matter) needs to know how it behaves. You need proper documentation anyway. > For instance: > > def append_str(str, append) > str << append > end > > def add_str(str, add) > str += add > end There is no point in implementing these methods. They do to little. And btw, you would rather do def add_str(str, add) str + add end > << operator changes the object itself so a will be changes, += creates a > new object so b won't be changed. Taking into account that Ruby uses > mainly references for each object (fixnum and company are the > exceptions) I hope this would be possible to include. Even if it was. I cannot recall ever having felt the need for this. This could mean anything from "my personal programming style is special in that it does not lead to code that would need references" to "the general Ruby style does not need references" - maybe you did not get the hang of it yet. The fact that you use pretty artificial examples seems to indicate that this is purely academic and there is no real programming need - even for yourself. Kind regards robert -- use.inject do |as, often| as.you_can - without end