Skip to content

Commit

Permalink
Add spec for overriding an optimized method through an already-prepen…
Browse files Browse the repository at this point in the history
…ded module
  • Loading branch information
eregon committed Apr 26, 2024
1 parent 4aba315 commit a608e54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/ruby/core/module/prepend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ def foo
foo.call.should == 'm'
end

it "updates the optimized method when a prepended module is updated" do
out = ruby_exe(<<~RUBY)
module M; end
class Integer
prepend M
end
l = -> { 1 + 2 }
p l.call
M.module_eval do
def +(o)
$called = true
super(o)
end
end
p l.call
p $called
RUBY
out.should == "3\n3\ntrue\n"
end

it "updates the method when there is a base included method and the prepended module overrides it" do
base_module = Module.new do
def foo
Expand Down
1 change: 1 addition & 0 deletions spec/tags/core/module/prepend_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fails:Module#prepend uses only new module when dupping the module
fails:Module#prepend prepends a module if it is included in a super class
fails:Module#prepend when module already exists in ancestor chain modifies the ancestor chain
slow:Module#prepend updates the optimized method when a prepended module is updated

0 comments on commit a608e54

Please sign in to comment.