Charlie wrote:
> Austin Ziegler wrote:
>> On 5/5/06, Charlie <peckcharlie / yahoo.com> wrote:
>>>         from (irb):7
>>>         from :0
>> 
>> Do you understand *why* that worked? Consider it from:
>> 
>>   A = "Foo"
>>   B = A
>>   B.freeze
>>   A << "Bar"
>> 
>> -austin
> 
> I show the object_id just for clarity, to show that A and B is 
> 'referencing' or 'pointing' to the same object, although they do 
> nothing. I thought I understand it until I try the example below for 
> integers. Instead of showing errors, it gave very large bogus numbers, 
> although results remain intact in the end. So, the answer to your 
> question is that I don't. I think I might have missed out something 
> here.
> 
> A = 10       => 10
> B = A        => 10
> B.freeze     => 10
> A << 20      => 10485760
> B << 40      => 10995116277760
> A            => 10
> B            => 10
> A.object_id  => 21
> B.object_id  => 21

Sorry, the leftshift results were consistent, but why doesn't the 
shifted result get stored back into pointer A like in the case of a 
string?

A = "foo"      => "foo"
X = A          => "foo"
A << "bar"     => "foobar"
A              => "foobar"
X              => "foobar"
A.object_id    => 29897204
X.object_id    => 29897204



-- 
Posted via http://www.ruby-forum.com/.