A = b = new

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?

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

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?

On 1/28/06, Xavier N. [email protected] 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