From: Robert Klemme Date: 2007-07-27T15:32:34+09:00 Subject: Re: How to pass arguments by reference in a function 2007/7/27, ashishwave : > if i pass arguments in a function then they get passed by value. how > to get it passed by reference. You can't. There are some solutions to this depending on situation: 1. inplace modification of arguments (Strings, Arrays, Hashes - all sorts of containers) 2. multiple return values 3. work with instance variables Generally in my experience it's not needed. > For example: if i want to swrite my own swap function (not using > multiple assignment syntax a,b=b,a) just for example example, how to > implement that in ruby irb(main):001:0> def swap(a,b) return b,a end => nil irb(main):002:0> x,y=1,2 => [1, 2] irb(main):003:0> x,y = swap x,y => [2, 1] irb(main):004:0> x => 2 irb(main):005:0> y => 1 But in reality you would just do x,y = y,x Kind regards robert