Skip to content

Commit

Permalink
Move Symbol#name into symbol.rb
Browse files Browse the repository at this point in the history
This allows to declare it as leaf just like `Symbol#to_s`.

Co-Authored-By: Étienne Barrié <[email protected]>
  • Loading branch information
byroot and etiennebarrie committed Nov 12, 2024
1 parent dc08d6e commit ae613a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down

0 comments on commit ae613a3

Please sign in to comment.