From: Tim Becker Date: 2007-03-14T20:25:38+09:00 Subject: Re: A simple question regarding ruby method argument > Can anyone point me how to pass > argument to method by reference? I mean that the methods/function able > to change the value of the argument. Values are always passed by reference: irb(main):011:0> class Test irb(main):012:1> attr_accessor :a irb(main):013:1> end irb(main):014:0> def modify x irb(main):015:1> x.a="hello" irb(main):016:1> end irb(main):017:0> t = Test.new irb(main):018:0> t.a="there" irb(main):019:0> modify t irb(main):020:0> t.a => "hello" what doesn't work is passing in a parameter `x`, assigning a new value to x within a function and expecting that assignment to be 'transfered' outside the function scope: def modify x x=2 # this doesn't work, because it modifies the reference and not # the referenced value end tmp=1 modify tmp # doesn't work as you'd like, tmp is still 1 puts tmp => 1 If you're familiar with Java, it's more or less the same behaviour. -Tim