Project

General

Profile

Actions

Bug #11182

closed

Refinement with alias causes strange behavior

Added by ko1 (Koichi Sasada) almost 9 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
-
[ruby-core:69360]
Tags:

Description

The following script causes strange behavior.

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 `<main>': undefined method `bar' for #<D:0x29fbf58> (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) 1.PNG ko1 (Koichi Sasada), 05/27/2015 05:15 AM
2.PNG (43.7 KB) 2.PNG ko1 (Koichi Sasada), 05/27/2015 05:15 AM
4.PNG (38.5 KB) 4.PNG ko1 (Koichi Sasada), 05/27/2015 05:34 AM
3.PNG (37.9 KB) 3.PNG ko1 (Koichi Sasada), 05/27/2015 05:34 AM
alias_affected_by_original_refinement.diff (1.34 KB) alias_affected_by_original_refinement.diff shugo (Shugo Maeda), 05/28/2015 07:54 AM
6.PNG (36.6 KB) 6.PNG ko1 (Koichi Sasada), 05/28/2015 09:12 AM
7.PNG (40.7 KB) 7.PNG ko1 (Koichi Sasada), 05/28/2015 09:12 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #13817: test/unit breaks HashClosedktsj (Kazuki Tsujimoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0