symbol_lookup3.patch

Matthew Kerwin, 03/09/2013 05:54 PM

Download (1.07 KB)

View differences:

string.c
7754 7754

  
7755 7755
/*
7756 7756
 *  call-seq:
7757
 *     Symbol[str]    => Symbol or nil
7758
 *
7759
 *  Returns an extant symbol, which is the .to_sym of +str+, or
7760
 *  nil if no such symbol exists.
7761
 *
7762
 *     Symbol['Object']      #=> :Object
7763
 *     Symbol['none such']   #=> nil
7764
 */
7765

  
7766
VALUE
7767
sym_lookup(VALUE cls, VALUE str)
7768
{
7769
    st_data_t id;
7770
    if (id = rb_check_id(&str)) {
7771
	return ID2SYM(id);
7772
    }
7773
    return Qnil;
7774
}
7775

  
7776

  
7777
/*
7778
 *  call-seq:
7757 7779
 *     sym == obj   -> true or false
7758 7780
 *
7759 7781
 *  Equality---If <i>sym</i> and <i>obj</i> are exactly the same
......
8307 8329
    rb_undef_alloc_func(rb_cSymbol);
8308 8330
    rb_undef_method(CLASS_OF(rb_cSymbol), "new");
8309 8331
    rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */
8332
    rb_define_singleton_method(rb_cSymbol, "[]", sym_lookup, 1);
8310 8333

  
8311 8334
    rb_define_method(rb_cSymbol, "==", sym_equal, 1);
8312 8335
    rb_define_method(rb_cSymbol, "===", sym_equal, 1);