Move Symbol#name into symbol.rb

This allows to declare it as leaf just like `Symbol#to_s`.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
This commit is contained in:
Jean Boussier 2024-11-12 11:53:35 +01:00
parent ae733a693b
commit bfb4783c01
2 changed files with 14 additions and 1 deletions

View File

@ -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);

View File

@ -14,6 +14,20 @@ class Symbol
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
#