# "double assignation" in a hash?

**URL:** <https://www.ruby-forum.com/t/double-assignation-in-a-hash/139568>\
**Category:** Rails\
**Created:** [June 5, 2008, 1:10am UTC](https://www.ruby-forum.com/t/double-assignation-in-a-hash/139568 "2008-06-05T01:10:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![itkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/22d042/32.png) [@itkin](https://www.ruby-forum.com/u/itkin)\
**Post date:** [June 5, 2008, 1:10am UTC](https://www.ruby-forum.com/t/double-assignation-in-a-hash/139568/1 "2008-06-05T01:10:54Z")

</div>

is it possible to make a quick "double assignation " in a hash like in  
php, for example :

a={}  
a[:b][:c]=“value”

---

<div class="post-metadata">

**Author:** ![itkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/22d042/32.png) [@itkin](https://www.ruby-forum.com/u/itkin)\
**Post date:** [June 5, 2008, 1:45am UTC](https://www.ruby-forum.com/t/double-assignation-in-a-hash/139568/2 "2008-06-05T01:45:09Z")

</div>

I don’t think so… why would you want to though? It’s not that much  
more code to say

value = whatever\_intecate\_algorithm\_or\_calculation\_you\_need  
a[:b] = value  
a[:c] = value

or

a{ a=\> value, b =\> value}

On Jun 4, 7:10 pm, nico Itkin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![itkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/22d042/32.png) [@itkin](https://www.ruby-forum.com/u/itkin)\
**Post date:** [June 5, 2008, 2:31am UTC](https://www.ruby-forum.com/t/double-assignation-in-a-hash/139568/3 "2008-06-05T02:31:54Z")

</div>

nico Itkin wrote:

> is it possible to make a quick "double assignation " in a hash like in  
> php, for example :
> 
> a={}  
> a[:b][:c]=“value”

it’s actually

> > a = {}  
> > =\> {}
> 
> > a[:a] = a[:b] = 1  
> > =\> 1
> 
> > a  
> > =\> {:a=\>1, :b=\>1}

script/console is your friend 🙂

Peace,  
Phillip
