Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update attach_before method.

Method attach_before should remember last parent. Without this we can
use prepend only once.
  • Loading branch information...
commit af3cbed4789b1287bcf8ae6e3a74dd725b8a5535 1 parent 84439a4
@LTe authored
View
22 kernel/alpha.rb
@@ -469,6 +469,14 @@ def direct_superclass
@superclass
end
+ def superclass_root
+ @superclass_root
+ end
+
+ def superclass_root=(other)
+ @superclass_root = other
+ end
+
# :internal:
#
# Perform actual work for including a Module in this one.
@@ -486,12 +494,6 @@ def append_features(mod)
#
def included(mod); end
- # Hook method called on Module when another Module is .prepend'd into it.
- #
- # Override for module-specific behaviour.
- #
- def prepended(mod); end
-
# :internal:
#
# Basic version of .include used in kernel code.
@@ -709,7 +711,13 @@ def attach_to(cls)
# Inject self before class
#
def attach_before(cls)
- @superclass = cls
+ if old_parent = cls.superclass_root
+ @superclass = old_parent
+ else
+ @superclass = cls
+ end
+
+ cls.superclass_root = self
end
# :internal:
View
4 spec/ruby/core/module/fixtures/classes.rb
@@ -414,13 +414,13 @@ def m1; [:C1, *super] end
module ModuleToPrepend
def m
- result = super if defined?(super)
+ result = super
[:m, result]
end
end
class ClassToPrepend
- prepend ModuleToPrepend if respond_to?(:prepend)
+ prepend ModuleToPrepend
def m
:c
end
View
2  spec/ruby/core/module/prepend_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-ruby_version_is "2.0" do
+ruby_version_is "1.9" do
describe "Module#prepend" do
it "prepends module do class" do
ModuleSpecs::ClassToPrepend.new.m.should == [:m, :c]
Please sign in to comment.
Something went wrong with that request. Please try again.