# \*args to Hash

**URL:** <https://www.ruby-forum.com/t/args-to-hash/71643>\
**Category:** Ruby\
**Created:** [October 10, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/args-to-hash/71643 "2006-10-10T15:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [October 10, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/args-to-hash/71643/1 "2006-10-10T15:30:55Z")

</div>

def foo(\*args)  
h = (Hash === args.last ? args.pop : {})  
args.each{|m| h[m]=m}  
args = h  
#…  
end

T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [October 10, 2006, 4:00pm UTC](https://www.ruby-forum.com/t/args-to-hash/71643/2 "2006-10-10T16:00:58Z")

</div>

Trans wrote:

> def foo(\*args)  
> h = (Hash === args.last ? args.pop : {})  
> args.each{|m| h[m]=m}  
> args = h  
> #…  
> end
> 
> T.

GOLF.

T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [October 10, 2006, 4:25pm UTC](https://www.ruby-forum.com/t/args-to-hash/71643/3 "2006-10-10T16:25:06Z")

</div>

On 10/10/06, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > T.
> 
> GOLF.
> 
> T.

“args.last ?”.sub(/.l…/, “[-1]”) ==\> -2

Most other WS can go away anyway so I guess you put them for  
Readability,  
like

“You know that cut I could have made it, but I wanted to make a three  
put on  
the last green for more readability ;)”

R.

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein
