# How to ducktype a Hash?

**URL:** <https://rubytalk.org/t/how-to-ducktype-a-hash/11978>\
**Category:** ruby-talk\
**Created:** [7 June 2004 19:44 UTC](https://rubytalk.org/t/how-to-ducktype-a-hash/11978 "2004-06-07T19:44:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Austin\_Ziegler](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Austin\_Ziegler](https://rubytalk.org/u/Austin_Ziegler)\
**Post date:** [7 June 2004 19:44 UTC](https://rubytalk.org/t/how-to-ducktype-a-hash/11978/1 "2004-06-07T19:44:50Z")

</div>

Richard Kilmer [mailto:rich@infoether.com] :

> Oops...sorry...you are right...it would have to be:
> 
> &nbsp;&nbsp;f.{Array}['rich']
> 
> to make it explicit that you are grouping the {} with the  
> method name. This is only an issue for the operator'ish methods  
> because methods require the dot in them already.

Maybe:

&nbsp;&nbsp;f\<Array\>['rich']  
&nbsp;&nbsp;f.\<Person\>[firstname]

It's ugly enough to discourage its use, but it also calls to mind the  
syntax for C++ templates (for good or ill) while not being  
currently-legal Ruby.

-austin

> **···**
>
> --  
> austin ziegler \* austin.ziegler@evault.com

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [7 June 2004 19:54 UTC](https://rubytalk.org/t/how-to-ducktype-a-hash/11978/2 "2004-06-07T19:54:28Z")

</div>

Hi --

> **···**
>
> On Tue, 8 Jun 2004, Austin Ziegler wrote:
> 
> > Richard Kilmer [mailto:rich@infoether.com] :  
> > \> Oops...sorry...you are right...it would have to be:  
> > \>  
> > \> f.{Array}['rich']  
> > \>  
> > \> to make it explicit that you are grouping the {} with the  
> > \> method name. This is only an issue for the operator'ish methods  
> > \> because methods require the dot in them already.
> > 
> > Maybe:
> > 
> > &nbsp;&nbsp;f\<Array\>['rich']  
> > &nbsp;&nbsp;f.\<Person\>[firstname]
> > 
> > It's ugly enough to discourage its use, but it also calls to mind the  
> > syntax for C++ templates (for good or ill) while not being  
> > currently-legal Ruby.
> 
> I think it has to be assumed that if Matz adds any type-related stuff,  
> it will get very heavy use, ugly or not. Luckily there's little or no  
> precedent for Matz adding ugly stuff 🙂 but I think this is a case  
> where people who want to use it are not going to be deterred by how it  
> looks, so I wouldn't want to rely on that effect.
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net
