diff --git a/string.c b/string.c index 93f94fdb4ac234..9f54289dae5627 100644 --- a/string.c +++ b/string.c @@ -12740,7 +12740,6 @@ Init_String(void) rb_define_method(rb_cSymbol, "==", sym_equal, 1); rb_define_method(rb_cSymbol, "===", sym_equal, 1); rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0); - rb_define_method(rb_cSymbol, "name", rb_sym2str, 0); /* in symbol.c */ rb_define_method(rb_cSymbol, "to_proc", rb_sym_to_proc, 0); /* in proc.c */ rb_define_method(rb_cSymbol, "succ", sym_succ, 0); rb_define_method(rb_cSymbol, "next", sym_succ, 0); diff --git a/symbol.rb b/symbol.rb index bfac11ae21b21d..458d02b177e8f3 100644 --- a/symbol.rb +++ b/symbol.rb @@ -14,6 +14,20 @@ def to_s alias id2name to_s + # call-seq: + # name -> string + # + # Returns a frozen string representation of +self+ (not including the leading colon): + # + # :foo.name # => "foo" + # :foo.name.frozen? # => true + # + # Related: Symbol#to_s, Symbol#inspect. + def name + Primitive.attr! :leaf + Primitive.cexpr! 'rb_sym2str(self)' + end + # call-seq: # to_sym -> self #