Skip to content

Commit

Permalink
Annotate Symbol#to_s as leaf (#9769)
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Jan 31, 2024
1 parent a322b2f commit 51753ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 0 additions & 13 deletions string.c
Expand Up @@ -11693,17 +11693,6 @@ sym_inspect(VALUE sym)
return str;
}

/*
* call-seq:
* to_s -> string
*
* Returns a string representation of +self+ (not including the leading colon):
*
* :foo.to_s # => "foo"
*
* Related: Symbol#inspect, Symbol#name.
*/

VALUE
rb_sym_to_s(VALUE sym)
{
Expand Down Expand Up @@ -12270,8 +12259,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, "to_s", rb_sym_to_s, 0);
rb_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 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);
Expand Down
15 changes: 15 additions & 0 deletions symbol.rb
@@ -1,4 +1,19 @@
class Symbol
# call-seq:
# to_s -> string
#
# Returns a string representation of +self+ (not including the leading colon):
#
# :foo.to_s # => "foo"
#
# Related: Symbol#inspect, Symbol#name.
def to_s
Primitive.attr! :leaf
Primitive.cexpr! 'rb_sym_to_s(self)'
end

alias id2name to_s

# call-seq:
# to_sym -> self
#
Expand Down

0 comments on commit 51753ec

Please sign in to comment.