From: Jim Weirich Date: 2005-01-20T07:39:14+09:00 Subject: Re: value by reference Glenn Parker said: > Perl generally uses call-by-value, but it also supports > call-by-reference using the backslash operator: > > sub inc { > $arg = shift @_; > $$arg += 1; > } > $x = 1; > inc(\$x); > print $x; Perl does it by creating a reference (with a backslash) and then dereferencing the reference (with an extra $). If you want the same in Ruby (with only a bit heavier syntax ... ref{:x} instead of \$x and arg.value instead of $$arg), you could write: def inc(arg) arg.value += 1 end x = 1 inc(ref{:x}) puts x # => 2 See http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc for details on how to implement ref. -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)