Skip to content

Commit

Permalink
Added Symbol#name
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Sep 4, 2020
1 parent d7406cc commit eb67c60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ Outstanding ones only.
* Symbol#to_proc now returns a lambda Proc.
[[Feature #16260]]

* New method

* Symbol#name, which returns the name of the symbol if it is
named. The returned string cannot be modified.
[[Feature #16150]]

* Warning

* Modified method
Expand Down Expand Up @@ -343,6 +349,7 @@ Excluding feature bug fixes.
[Feature #16378]: https://bugs.ruby-lang.org/issues/16378
[Feature #16828]: https://bugs.ruby-lang.org/issues/16828
[Bug #14541]: https://bugs.ruby-lang.org/issues/14541
[Feature #16150]: https://bugs.ruby-lang.org/issues/16150
[Feature #16175]: https://bugs.ruby-lang.org/issues/16175
[Feature #15973]: https://bugs.ruby-lang.org/issues/15973
[Feature #16614]: https://bugs.ruby-lang.org/issues/16614
Expand Down
1 change: 1 addition & 0 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -11539,6 +11539,7 @@ Init_String(void)
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);
rb_define_method(rb_cSymbol, "intern", sym_to_sym, 0);
rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
rb_define_method(rb_cSymbol, "to_proc", rb_sym_to_proc, 0);
Expand Down
6 changes: 6 additions & 0 deletions test/ruby/test_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def test_inspect
end
end

def test_name
assert_equal("foo", :foo.name)
assert_same(:foo.name, :foo.name)
assert_predicate(:foo.name, :frozen?)
end

def test_to_proc
assert_equal %w(1 2 3), (1..3).map(&:to_s)
[
Expand Down

0 comments on commit eb67c60

Please sign in to comment.