Hi --

On Wed, 14 May 2008, Sebastian Hungerecker wrote:

> Paul Dugdale wrote:
>> What I was trying to find out is - is there any way of passing a
>> reference to the value to the 'each' block, rather than a copy of the
>> value.
>
> You always pass by reference, but you pass a reference to the object (a
> pointer if you will) not a reference to the variable. You can't have variable
> references in ruby.

I'd put it differently, and I know this sounds convoluted but I think
in the end it turns out to be more apt: You're passing by value, but
the value you're passing is a reference to an object.

"Passing by reference" makes it sound (to me) like when you do this:

   s = "hi"
   my_method(s)

s somehow gets wrapped in a reference on its way to my_method, whereas
it's actually really just being handed off. The value assigned to the
corresponding parameter in my_method is the same as the value of s:
namely, a reference to that string.

There's probably some aspect of using literal constructors as method
arguments that needs to be factored in there somewhere....


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
   INTRO TO RAILS         June 24-27           London (Skills Matter)
See http://www.rubypal.com for details and updates!