Issue #7854 has been updated by phluid61 (Matthew Kerwin).

File symbol_lookup3.patch added
File symbol_lookup3_warn.patch added

nobu (Nobuyoshi Nakada) wrote:
> Why does it have -1 arity?
> 
> And I don't think it's harmful if the method allows a Smbol too.

To the first: an oversight on my part, there's no real reason.  I have rewritten it with an arity of 1.

To the second: I can easily change it to allow a Symbol as well.  However since the original discussion that spawned this proposal was focused on the idea of not creating unwanted/unneeded Symbols, I wonder should it emit a warning in that case?

I see now, too, that I was rather overzealous in my original attempts.  I should have realised most of the hard work has already been done.  :)

Now I suppose it's up to Matz to approve it or not.
----------------------------------------
Feature #7854: New method Symbol[string]
https://bugs.ruby-lang.org/issues/7854#change-37420

Author: Student (Nathan Zook)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


I propose a new class method [] on Symbol.  If a symbol s already exists such that s.to_s == string, then s is returned.  If not, nil is returned.

The inspiration for this method is a question I was asked, and the answer I was given:  "Why would you want to turn a tainted string into a symbol?"  "I don't--I want to access an existing symbol with tainted data".  Symbol[] accesses the symbol table like hash[] accesses the elements of a hash.

I believe that this completely addresses the problems behind tickets #7791 and #7839.  I believe that it is a more intuitive solution than my proposal #7795, and I believe that this will also be useful for YAML.safe_load and similar initiatives.



-- 
http://bugs.ruby-lang.org/