symbol_lookup3_warn.patch

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

Download (1.16 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 (SYMBOL_P(str)) {
7771
	rb_warn("Symbol passed to Symbol[]");
7772
	return str;
7773
    }
7774
    if (id = rb_check_id(&str)) {
7775
	return ID2SYM(id);
7776
    }
7777
    return Qnil;
7778
}
7779

  
7780

  
7781
/*
7782
 *  call-seq:
7757 7783
 *     sym == obj   -> true or false
7758 7784
 *
7759 7785
 *  Equality---If <i>sym</i> and <i>obj</i> are exactly the same
......
8307 8333
    rb_undef_alloc_func(rb_cSymbol);
8308 8334
    rb_undef_method(CLASS_OF(rb_cSymbol), "new");
8309 8335
    rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */
8336
    rb_define_singleton_method(rb_cSymbol, "[]", sym_lookup, 1);
8310 8337

  
8311 8338
    rb_define_method(rb_cSymbol, "==", sym_equal, 1);
8312 8339
    rb_define_method(rb_cSymbol, "===", sym_equal, 1);