Project

General

Profile

Actions

Bug #15437

closed

正規表現の名前付きキャプチャでASCII以外の大文字で定義したクラスが上書きされる

Added by hanachin (Seiei Miyagi) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 2.6.0rc2 (2018-12-15 trunk 66408) [x86_64-linux]
[ruby-dev:50719]

Description

ASCIIの大文字で定義したクラスは正規表現の名前付きキャプチャで上書きされませんが、ASCII以外の大文字で定義したクラスは上書きされてしまうようです。
これは意図的ですか?

# rewrite_constant_by_named_capture.rb
class C
end

/(?<C>C)/ =~ "C"

p C

class 𝐂
end

/(?<𝐂>𝐂)/ =~ "𝐂"

p 𝐂

C.new
𝐂.new
% ruby -v rewrite_constant_by_named_capture.rb
ruby 2.6.0rc2 (2018-12-15 trunk 66408) [x86_64-linux]
C
rewrite_constant_by_named_capture.rb:11: warning: already initialized constant 𝐂
rewrite_constant_by_named_capture.rb:8: warning: previous definition of 𝐂 was here
"𝐂"
Traceback (most recent call last):
rewrite_constant_by_named_capture.rb:16:in `<main>': undefined method `new' for "𝐂":String (NoMethodError)
Did you mean?  next
Actions

Also available in: Atom PDF