A = b = new


#1

Hi there.

I’m coming to ruby mainly from python background.

in python
a = b = range(10)

will yields two names pointing to the same object

but in ruby

a = b = Range.new(0,9)

will yield two two distinct objects.

To get the effect of the python line in ruby it seems I have to do:
b = Range.new(0,9)
a = b

What’s the logic behind that?


#2

On Jan 28, 2006, at 14:47, Alex P. wrote:

a = b = Range.new(0,9)

will yield two two distinct objects.

See this session:

irb(main):001:0> a = b = Range.new(0, 9)
=> 0…9
irb(main):002:0> a.object_id
=> 1744024
irb(main):003:0> b.object_id
=> 1744024

– fxn


#3

Alex P. wrote:

in python
a = b = range(10)

will yields two names pointing to the same object

but in ruby

a = b = Range.new(0,9)

will yield two two distinct objects.

Actually, it won’t.

How did you come to this conclusion?


#4

On 1/28/06, Xavier N. removed_email_address@domain.invalid wrote:

See this session:

irb(main):001:0> a = b = Range.new(0, 9)
=> 0…9
irb(main):002:0> a.object_id
=> 1744024
irb(main):003:0> b.object_id
=> 1744024

Did just that. Should have done it twice I guess :slight_smile:

alex