# Prop = x =\> y

**URL:** <https://www.ruby-forum.com/t/prop-x-y/96059>\
**Category:** Ruby\
**Created:** [June 24, 2006, 1:42pm UTC](https://www.ruby-forum.com/t/prop-x-y/96059 "2006-06-24T13:42:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roggan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@roggan](https://www.ruby-forum.com/u/roggan)\
**Post date:** [June 24, 2006, 1:42pm UTC](https://www.ruby-forum.com/t/prop-x-y/96059/1 "2006-06-24T13:42:11Z")

</div>

Why cant I do things like:

my\_prop = :foo =\> :bar

when its possible to do:

my\_meth :foo =\> :bar

??

ive tried with  
my\_prop = (:foo =\> :bar)  
to but no luck…

//Roger

---

<div class="post-metadata">

**Author:** ![roggan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@roggan](https://www.ruby-forum.com/u/roggan)\
**Post date:** [June 24, 2006, 1:52pm UTC](https://www.ruby-forum.com/t/prop-x-y/96059/2 "2006-06-24T13:52:49Z")

</div>

also , is it wrong to use the x =\> y construct in other context than  
describing hashtables?

in my case my idea was to associate symbols with values in a sort of  
.net attribute/annotation way

"  
meta.some\_prop= :parent\_of =\> [:sometype,:someprop]  
attr\_accessor :some\_prop  
"

it works just fine for everything except for set properties. (whatever  
you might call them in ruby)

"  
meta.my\_meth :foo =\> :bar  
def my\_meth()  
end  
"

works just fine…  
(the “meta” is an extended method on Class which returns an attribute  
object which in turn handles method\_missing and then stores the  
class,methodid and data in a static lookup)

---

<div class="post-metadata">

**Author:** ![roggan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@roggan](https://www.ruby-forum.com/u/roggan)\
**Post date:** [June 24, 2006, 2:00pm UTC](https://www.ruby-forum.com/t/prop-x-y/96059/3 "2006-06-24T14:00:24Z")

</div>

Hi –

On Sat, 24 Jun 2006, Roger J. wrote:

> ive tried with  
> my\_prop = (:foo =\> :bar)  
> to but no luck…

You need to use the hash literal constructor:

my\_prop = { :foo =\> :bar }

The only time you’re allowed _not_ to use it, and still have Ruby know  
that you’re trying to construct a hash, is the special case of a  
method call:

my\_meth :a =\> “b”, :c =\> “d”

which is equivalent to:

my\_meth({:a =\> “b”, :c =\> “d”})

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

See what the readers are saying about “Ruby for Rails”!

> **[Ruby on Rails Framework | Ruby Power and Light](https://www.rubypowerandlight.com/)**
>
> Main aspects of the Ruby language with focus on Rails - the most widespread and powerful Web Application Framework of the language, which implements the MVC pattern.

---

<div class="post-metadata">

**Author:** ![roggan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@roggan](https://www.ruby-forum.com/u/roggan)\
**Post date:** [June 24, 2006, 2:00pm UTC](https://www.ruby-forum.com/t/prop-x-y/96059/4 "2006-06-24T14:00:40Z")

</div>

When you do my\_method :foo =\> :bar Ruby turns this in to  
my\_method({:foo =\> :bar}) to provide a pseudo-keyword-argument system.  
This isn’t legal anywhere else in Ruby code.

---

<div class="post-metadata">

**Author:** ![roggan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@roggan](https://www.ruby-forum.com/u/roggan)\
**Post date:** [June 24, 2006, 2:04pm UTC](https://www.ruby-forum.com/t/prop-x-y/96059/5 "2006-06-24T14:04:02Z")

</div>

Hi –

On Sat, 24 Jun 2006, Roger J. wrote:

> also , is it wrong to use the x =\> y construct in other context than  
> describing hashtables?

I don’t know of any meaning for =\> other than hash separator.

> class,methodid and data in a static lookup)  
> Be advised: nothing is static in Ruby 🙂

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

See what the readers are saying about “Ruby for Rails”!

> **[Ruby on Rails Framework | Ruby Power and Light](https://www.rubypowerandlight.com/)**
>
> Main aspects of the Ruby language with focus on Rails - the most widespread and powerful Web Application Framework of the language, which implements the MVC pattern.
