Ruby 2.0: Symbol uniqueness?

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

p “!”.intern == “[email protected]”.intern # => true
p “-(unary)”.intern == “[email protected]”.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 “[email protected]
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

This may be a question for the Ruby Core list?

MenTaLguY [email protected] 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

On 5/5/06, MenTaLguY [email protected] 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
[email protected]
http://shadsterling.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs