From: headius@... Date: 2015-05-28T22:31:03+00:00 Subject: [ruby-core:69400] [Ruby trunk - Bug #11182] Refinement with alias causes strange behavior Issue #11182 has been updated by Charles Nutter. Assignee changed from Koichi Sasada to Shugo Maeda Alias does not redispatch, so this is the result I'd expect. These are some of the edge cases that I don't think we can solve for everyone. Bottom line is that method table changes are method table changes. The only way we could implement this the way you want would be to have aliased methods redispatch to the original name, which has all sorts of really nasty problems (redispatch from bottom class or current class? super reflects new name or old name?). I don't think we can do it ko1's way without introducing many more significant problems (by changing what alias means). ---------------------------------------- Bug #11182: Refinement with alias causes strange behavior https://bugs.ruby-lang.org/issues/11182#change-52673 * Author: Koichi Sasada * Status: Feedback * Priority: Normal * Assignee: Shugo Maeda * ruby -v: 2.3dev * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- 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" ``` ---Files-------------------------------- 1.PNG (38.7 KB) 2.PNG (43.7 KB) 4.PNG (38.5 KB) 3.PNG (37.9 KB) alias_affected_by_original_refinement.diff (1.34 KB) 6.PNG (36.6 KB) 7.PNG (40.7 KB) -- https://bugs.ruby-lang.org/