Direct access to global_symbols from extension

Hello,

I am working on a small gem and I need kind of a direct access to
symbols table. Specifically, I would like to test whether particular
Symbol is already present in the table.

Using inline gem, when I refer to global_symbols directly, naturally I
get error:

/home/jrusnack/workspace/safe-intern/lib/safe-intern/exception_patch.rb:9:
error: ‘global_symbols’ undeclared (first use in this function)

The only two functions that call st_lookup(global_symbols,..) are
rb_intern3 and rb_id2str - I don`t see how to use either of them to
query the global_symbols without defining new symbol.

Is there any workaround for this ?

Thanks !

···

--
Posted via http://www.ruby-forum.com/.

Hello,

I am working on a small gem and I need kind of a direct access to
symbols table. Specifically, I would like to test whether particular
Symbol is already present in the table.

Symbol.find just appeared in ruby-trunk and will be in the 2.2.0 release
(December?)

Is there any workaround for this ?

You can backport r45175 from trunk to your version of Ruby.

Otherwise, you can try using Symbol.all_symbols (possibly caching the
output) to check.

···

Jan Rusnacko <lists@ruby-forum.com> wrote:

Thank you guys, much appreciated ! Yes, is exactly what I was looking
for, but I was looking for it in 1.9.3 ...

Matthew: Thanks for a cool gem ! Will definitely promote it :wink:

···

--
Posted via http://www.ruby-forum.com/.

Sorry, not awake yet :x rb_check_id should be available, too.

···

Eric Wong <normalperson@yhbt.net> wrote:

Jan Rusnacko <lists@ruby-forum.com> wrote:
> Is there any workaround for this ?

There's also this: https://rubygems.org/gems/symbol_lookup

Full source code is available on github.