Project

General

Profile

Bug #15437

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

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

 ```ruby ```rb 
 # 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 
 ```

Back