From: caof2005 Date: 2007-07-26T04:15:02+09:00 Subject: Re: Question - Passing parameters by reference Thanks for the response, although I was just wondering that using Strings as a parameters in a method definition is a special case. Let me explain.... I observed that when you use a string as a parameter in a method definition, it can be changed by applying several operations inside the method, for instance you can change it, by adding letters to the string, changing the content to uppercase etc. So I figured out that when you use a string, what really happens inside the method is that you don't create a new object, you just use the reference. In opposition as if you use other kind of parameters in a method definition, let say for example an int variable. If you try to change this int variable inside the method, it simply doesn't work, what happens is that you get a "copy" of the object that you're passing but after the method is finished, that copy disappears and at the end the parameter that you passed was not affected. Am I correct with my conclusions? Regards Carlos On Jul 25, 11:35 am, dbl...@wobblini.net wrote: > Hi -- > > On Thu, 26 Jul 2007, Chris Thiel wrote: > > What if the method is returning something else already and you don't want > > to have to return the changed value? How do you pass in a variable to a > > method and have the change stick when it exists the method in ruby? > > You can change an object: > > def change_me(str) > str.upcase! > end > > s = "abc" > change_me(str) > puts s # ABC > > But you can't change the bindings. In the example, I've got s and str > both containing references to the same string. But the names of the > identifiers themselves, s and str, are solely the business of their > local scopes, which are different as between the method body and the > calling context. > > David > > -- > * Books: > RAILS ROUTING (new!http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)