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 !

Jan R. [email protected] wrote:

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.

Eric W. [email protected] wrote:

Jan R. [email protected] wrote:

Is there any workaround for this ?

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

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:

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

Full source code is available on github.

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