Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define a convention for descendants and subclasses.
The former should be symmetric with ancestors and include all children. However, it should not include self since ancestors + descendants should not have duplicated. The latter is symmetric to superclass in the sense it only includes direct children. By adopting a convention, we expect to have less conflict with other frameworks, as Datamapper. For this moment, to ensure ActiveModel::Validations can be used with Datamapper, we should always call ActiveSupport::DescendantsTracker.descendants(self) internally instead of self.descendants avoiding conflicts.
- Loading branch information
Showing
13 changed files
with
100 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
activesupport/lib/active_support/core_ext/object/extending.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
require 'abstract_unit' | ||
require 'active_support/core_ext/class' | ||
|
||
class A | ||
end | ||
class ClassTest < Test::Unit::TestCase | ||
class Parent; end | ||
class Foo < Parent; end | ||
class Bar < Foo; end | ||
class Baz < Bar; end | ||
|
||
module X | ||
class B | ||
end | ||
end | ||
class A < Parent; end | ||
class B < A; end | ||
class C < B; end | ||
|
||
module Y | ||
module Z | ||
class C | ||
end | ||
def test_descendants | ||
assert_equal [Foo, Bar, Baz, A, B, C], Parent.descendants | ||
assert_equal [Bar, Baz], Foo.descendants | ||
assert_equal [Baz], Bar.descendants | ||
assert_equal [], Baz.descendants | ||
end | ||
end | ||
|
||
class ClassTest < Test::Unit::TestCase | ||
def test_retrieving_subclasses | ||
@parent = eval("class D; end; D") | ||
@sub = eval("class E < D; end; E") | ||
@subofsub = eval("class F < E; end; F") | ||
assert_equal 2, @parent.subclasses.size | ||
assert_equal [@subofsub.to_s], @sub.subclasses | ||
assert_equal [], @subofsub.subclasses | ||
assert_equal [@sub.to_s, @subofsub.to_s].sort, @parent.subclasses.sort | ||
def test_subclasses | ||
assert_equal [Foo, A], Parent.subclasses | ||
assert_equal [Bar], Foo.subclasses | ||
assert_equal [Baz], Bar.subclasses | ||
assert_equal [], Baz.subclasses | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a5dda97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/me applauds the guide patch :)