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:
parent
ae733a693b
commit
bfb4783c01
1
string.c
1
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);
|
||||
|
14
symbol.rb
14
symbol.rb
@ -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
|
||||
#
|
||||
|
Loading…
x
Reference in New Issue
Block a user