From: Lyle Johnson Date: 2004-02-09T08:53:35+09:00 Subject: Re: ruby and pointers Elias Athanasopoulos wrote: > Suppose: > > pool = [1.2, 2.434, 1.132, 1.1334] > foo = 0.0 > pool.each do |x| > foo = x # foo changes value and actual address in mem > end > > Can I give foo the value *only* of x but not change its > actual address in memory? I don't think so, because foo is a reference to a Float object, and Float objects are immutable. In contrast, if foo were a reference to some kind of mutable object (like a String), you *could* change its value without creating a new object in the process, e.g. foo = "a string" puts foo.id foo.sub!("a", "the") puts foo.id # should be the same as before the sub! Hope this helps, Lyle