# Ruby 2.0: Symbol uniqueness?

**URL:** <https://www.ruby-forum.com/t/ruby-2-0-symbol-uniqueness/59712>\
**Category:** Ruby\
**Created:** [May 5, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/ruby-2-0-symbol-uniqueness/59712 "2006-05-05T18:18:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [May 5, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/ruby-2-0-symbol-uniqueness/59712/1 "2006-05-05T18:18:03Z")

</div>

I just learned yesterday that different string values can intern to the  
same symbols; for example:

p “!”.intern == “!@”.intern # =\> true  
p “-(unary)”.intern == “-@”.intern # =\> true

There aren’t many such cases, but it makes life awkward if you’re  
writing code where two such strings are valid input (e.g. “!” and “!@”  
are both valid, if unusual, identifiers in Scheme s-expressions).

This seems to be a side-effect of the current implementation of unary  
operators in Ruby 1.x – is it slated for change in Ruby 2.0?

I think it’d be nice if Ruby symbols were guaranteed to uniquely  
represent string values, and x.intern.to\_s == x were an invariant for  
non-empty strings.

-mental

---

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [May 5, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/ruby-2-0-symbol-uniqueness/59712/2 "2006-05-05T18:45:58Z")

</div>

This may be a question for the Ruby Core list?

---

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [May 8, 2006, 2:09pm UTC](https://www.ruby-forum.com/t/ruby-2-0-symbol-uniqueness/59712/3 "2006-05-08T14:09:03Z")

</div>

MenTaLguY [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I think it’d be nice if Ruby symbols were guaranteed to uniquely  
> represent string values, and x.intern.to\_s == x were an invariant  
> for non-empty strings.

+1

---

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [May 11, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/ruby-2-0-symbol-uniqueness/59712/4 "2006-05-11T20:43:56Z")

</div>

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

> I think it’d be nice if Ruby symbols were guaranteed to uniquely represent  
> string values, and x.intern.to\_s == x were an invariant for non-empty  
> strings.

+1

-mental

> 

–

Shad Sterling  
removed\_email\_address@domain.invalid  
[http://shadsterling.com](http://shadsterling.com)
