On Feb 8, 3:33 pm, David Kahn <[email protected]> wrote:
> On Tue, Feb 8, 2011 at 9:06 AM, Frederick Cheung <[email protected]
>
> I see, I guess I got confused as I use ActiveRecord so much and within a
> each block, by setting values and calling save it of course saves the
> object. Is there a way to achieve what I am presenting, though, passing a
> batch of variables and having them operated on and changed?

that is very different. doing  some_object.foo = 'bar' is calling a
method on an object that changes its state, whereas
foo = bar just points a local variable at something new. (and in
addition Fixnums/BigDecimal are immutable - there is no method you can
call on a number to change it into another nmber)

>
> Excuse my ingenuity, but I am trying to understand... if I have an array of
> variables it seems that when the array is created, the elements which were
> variables are substituted by values, and there is no reference:


> (rdb:1) arr = [v1,v2,v3]
> [1, 2, 3]

Without resorting to dirty tricks, you can't change the values of
local variables other than by actually doing
v1 = 2. arr does NOT contain [v1,v2,v3]. It contains 3 objects, and
the local variables v1,v2,v3 just happen to also be referencing those
same objects.

Fred

> (rdb:1) v1
> 1
> (rdb:1) arr[0]=5
> 5
> (rdb:1) v1
> 1
>
> This must sound like kindergarten but apparently I have been working albeit
> successfully under some very false premises.
>
>
>
>
>
> > Fred
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ruby on Rails: Talk" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to