A gemified version of the Symbol[str] method proposed in https://bugs.ruby-lang.org/issues/7854
Ruby C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ext/symbol_lookup
lib
test
.gitignore
.travis.yml
CHANGELOG.md
Gemfile
LICENSE
README.md
Rakefile
code_of_conduct.md
symbol_lookup.gemspec

README.md

Symbol Lookup Gem

A gemified version of the Symbol[str] method proposed in https://bugs.ruby-lang.org/issues/7854

 call-seq:
    Symbol.find str => Symbol or nil
    Symbol[str]   => Symbol or nil
    str.interned? => Symbol or nil
    str.to_existing_sym => Symbol or ArgumentError

Returns an extant symbol, which is the .to_sym of str, or nil if no such symbol exists.

Symbol.find 'Object' #=> :Object
Symbol.find 'none such' #=> nil
Symbol['Object'] #=> :Object
Symbol['none such'] #=> nil

'Object'.interned? #=> :Object
'none such'.interned? #=> nil

'Object'.to_existing_sym #=> :Object
'none such'.to_existing_sym #=> (raises ArgumentError)