Skip to content

Commit a608e54

Browse files
committed
Add spec for overriding an optimized method through an already-prepended module
1 parent 4aba315 commit a608e54

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

spec/ruby/core/module/prepend_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ def foo
7575
foo.call.should == 'm'
7676
end
7777

78+
it "updates the optimized method when a prepended module is updated" do
79+
out = ruby_exe(<<~RUBY)
80+
module M; end
81+
class Integer
82+
prepend M
83+
end
84+
l = -> { 1 + 2 }
85+
p l.call
86+
M.module_eval do
87+
def +(o)
88+
$called = true
89+
super(o)
90+
end
91+
end
92+
p l.call
93+
p $called
94+
RUBY
95+
out.should == "3\n3\ntrue\n"
96+
end
97+
7898
it "updates the method when there is a base included method and the prepended module overrides it" do
7999
base_module = Module.new do
80100
def foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fails:Module#prepend uses only new module when dupping the module
22
fails:Module#prepend prepends a module if it is included in a super class
33
fails:Module#prepend when module already exists in ancestor chain modifies the ancestor chain
4+
slow:Module#prepend updates the optimized method when a prepended module is updated

0 commit comments

Comments
 (0)