# A = b = new

**URL:** <https://www.ruby-forum.com/t/a-b-new/98243>\
**Category:** Ruby\
**Created:** [January 28, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/a-b-new/98243 "2006-01-28T14:50:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alex789](https://www.ruby-forum.com/u/alex789)\
**Post date:** [January 28, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/a-b-new/98243/1 "2006-01-28T14:50:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alex789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alex789](https://www.ruby-forum.com/u/alex789)\
**Post date:** [January 28, 2006, 2:56pm UTC](https://www.ruby-forum.com/t/a-b-new/98243/2 "2006-01-28T14:56:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alex789](https://www.ruby-forum.com/u/alex789)\
**Post date:** [January 28, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/a-b-new/98243/3 "2006-01-28T14:59:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alex789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alex789](https://www.ruby-forum.com/u/alex789)\
**Post date:** [January 28, 2006, 3:14pm UTC](https://www.ruby-forum.com/t/a-b-new/98243/4 "2006-01-28T15:14:20Z")

</div>

On 1/28/06, Xavier N. [removed\_email\_address@domain.invalid](mailto: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 🙂

alex
