ruby/symbol.rb
Jean Boussier 2c574ca7e2 Symbol#to_s now returns a frozen string.
[Feature #22137]

It has returned a chilled string, hence emitting deprecation
warnings for two versions.
2026-07-10 10:02:00 +02:00

40 lines
731 B
Ruby

class Symbol
# call-seq:
# to_s -> string
#
# Returns a frozen string representation of +self+ (not including the leading colon):
#
# :foo.to_s # => "foo"
# :foo.name.frozen? # => true
#
# Related: Symbol#inspect
def to_s
Primitive.attr! :leaf
Primitive.cexpr! 'rb_sym2str(self)'
end
alias id2name to_s
alias name to_s
# call-seq:
# empty? -> true or false
#
# Returns +true+ if +self+ is <tt>:''</tt>, +false+ otherwise.
def empty?
Primitive.attr! :leaf
Primitive.cexpr! 'RBOOL(RSTRING_LEN(rb_sym2str(self)) == 0)'
end
# call-seq:
# to_sym -> self
#
# Returns +self+.
#
# Related: String#to_sym.
def to_sym
self
end
alias intern to_sym
end