Feature #5072 » 0001-Add-String-interned-for-checking-if-a-string-is-alre.patch
include/ruby/intern.h | ||
---|---|---|
int rb_is_local_id(ID);
|
||
int rb_is_junk_id(ID);
|
||
int rb_symname_p(const char*);
|
||
int rb_sym_interned_p(VALUE);
|
||
VALUE rb_str_interned_p(VALUE);
|
||
void rb_gc_mark_symbols(void);
|
||
VALUE rb_backref_get(void);
|
||
void rb_backref_set(VALUE);
|
parse.y | ||
---|---|---|
return ary;
|
||
}
|
||
VALUE
|
||
rb_str_interned_p(VALUE str)
|
||
{
|
||
st_data_t data;
|
||
if (st_lookup(global_symbols.sym_id, (st_data_t)str, &data))
|
||
return Qtrue;
|
||
return Qfalse;
|
||
}
|
||
int
|
||
rb_is_const_id(ID id)
|
||
{
|
string.c | ||
---|---|---|
rb_define_method(rb_cString, "force_encoding", rb_str_force_encoding, 1);
|
||
rb_define_method(rb_cString, "valid_encoding?", rb_str_valid_encoding_p, 0);
|
||
rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
|
||
rb_define_method(rb_cString, "interned?", rb_str_interned_p, 0); /* in parse.y */
|
||
id_to_s = rb_intern("to_s");
|
||
test/ruby/test_parse.rb | ||
---|---|---|
assert(x.all? {|s| s.is_a?(Symbol) })
|
||
end
|
||
def test_string_interned
|
||
str = "test_string_interned"
|
||
assert str.interned?
|
||
assert Symbol.all_symbols.any?{|sym| sym.to_s == str}
|
||
str = "gadzooks!123"
|
||
assert !str.interned?
|
||
assert !Symbol.all_symbols.any?{|sym| sym.to_s == str}
|
||
end
|
||
def test_is_class_id
|
||
c = Class.new
|
||
assert_raise(NameError) do
|