From: ko1@... Date: 2015-05-26T19:08:49+00:00 Subject: [ruby-core:69368] [Ruby trunk - Bug #11182] Refinement with alias causes strange behavior Issue #11182 has been updated by Koichi Sasada. Simplify example: ```ruby class C def foo p "C" end end module M refine C do def foo p "Refiend C" end end end class C alias bar foo end C.new.foo C.new.bar using M C.new.foo C.new.bar ``` ``` C.new.foo # C C.new.bar # C using M C.new.foo # refined C C.new.bar # C ``` I agree that invoking only "C" is reasonable because it can be direct pointer to C#foo. However, I think it is also reasonable to call refined C because people can assume C#bar should be same as C#foo. ---------------------------------------- Bug #11182: Refinement with alias causes strange behavior https://bugs.ruby-lang.org/issues/11182#change-52642 * Author: Koichi Sasada * Status: Closed * Priority: Normal * Assignee: Shugo Maeda * ruby -v: 2.3dev * Backport: 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED ---------------------------------------- The following script causes strange behavior. ```ruby class C def foo p "C" end end module M refine C do def foo p "Refiend C" end end end class D < C alias bar foo end using M D.new.bar #=> t.rb:21:in `
': undefined method `bar' for # (NoMethodError) ``` It seems strange. Maybe (1) C#foo or (2) M#C#foo should be called. But I'm not sure which is suitable. Previous versions: ``` ruby 2.0.0p606 (2014-11-28 revision 48636) [i386-mswin32_110] t.rb:9: warning: Refinements are experimental, and the behavior may change in future versions of Ruby! "C" ruby 2.1.5p312 (2015-03-10 revision 49912) [i386-mswin32_110] "C" ``` -- https://bugs.ruby-lang.org/