From: Ken Bloom Date: 2008-11-27T11:05:19+09:00 Subject: Re: How to use a passing argument(returned argument)? On Tue, 25 Nov 2008 23:38:02 -0500, Einar Magnç‚­s Boson wrote: > > I did not know this, google filled me in and this might be relevant to > the original question: > http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc/style/print > > They end up with this: > > def swap(aref, bref) > aref.value, bref.value = bref.value, aref.value end > > a = 22 > b = 33 > swap(ref{:a}, ref{:b}) > p a # => 33 > p b # => 22 > > Pretty neat, if that's something you wanna do. That rocks. Thanks for sharing. I thought that this kind of functionality would require syntax built into the language. > Makes me wonder though: > when I first saw this (5 minutes ago) I thought you might be able to do > > a = 0 > > def set10(aArg_name, bind=binding) > eval("#{aArg_name} = 10", bind) > end > > set10('a') > > p a > > > but that doesn't work, in what context and when are default-values > evaluated? my guess is that they get the same closure as the method body > and are evaluated on call, is that correct? Yeah. I'd love to have a Binding.of_caller or something like that, but have had no such luck. (Ok. It's an add-on in 1.8, but I'm curious about 1.9) -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/