Module: SafeIntern
- Defined in:
- lib/safe_intern/nil_patch.rb,
lib/safe_intern/exception_patch.rb,
ext/symbol_defined/symbol_defined.c
Overview
Copyright © 2014 Jan Rusnacko
This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the MIT license.
Defined Under Namespace
Modules: ExceptionPatch, NilPatch
Class Method Summary collapse
Class Method Details
.symbol_defined?(str) ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'ext/symbol_defined/symbol_defined.c', line 26
VALUE
symbol_defined(VALUE self, VALUE str)
{
int i;
VALUE string;
st_data_t data;
ID to_s;
VALUE symbols;
to_s = rb_intern("to_s");
// extremely slow, but necessary to see when new symbol has been added
symbols = rb_sym_all_symbols();
if(cached_symbols == NULL || cached_symbols->num_entries != RARRAY_LEN(symbols)){
cached_symbols = st_init_strtable_with_size(2000);
for (i = 0; i < RARRAY_LEN(symbols); i++)
{
string = rb_funcall(rb_ary_entry(symbols, i), to_s, 0, NULL);
st_add_direct(cached_symbols, (st_data_t)StringValueCStr(string), NULL);
}
}
if (st_lookup(cached_symbols, StringValueCStr(str), &data)) {
return Qtrue;
} else {
return Qfalse;
}
}
|