Created
March 25, 2011 16:00
-
-
Save guilhermesilveira/887082 to your computer and use it in GitHub Desktop.
checking for coupling and encapsulation fails
This file contains hidden or 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
class BasicObject | |
def self.include(m) | |
puts "#{m.ancestors} are coupling and breaking encapsulation of #{self}. are you sure you want to do that, my boy?" | |
super(m) | |
end | |
end | |
module B | |
end | |
module C | |
include B | |
end | |
class A | |
include C | |
end |
This file contains hidden or 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
class BasicObject | |
def self.accept(who) | |
![BasicObject, ::Object, ::Kernel, ::Module, ::Enumerable, ::Comparable, ::Struct].include?(who) | |
end | |
def self.include(*types) | |
self.ancestors.each do |my| | |
types.each { |m| | |
m.ancestors.each { |k| | |
puts "\"#{k}\" -- \"#{m}\"" if accept(k) && accept(m) && k!=m | |
puts "\"#{my}\" -- \"#{k}\"" if accept(k) && accept(my) && k!=my | |
} | |
} | |
end | |
super(*types) | |
end | |
end | |
module B | |
end | |
module C | |
include B | |
end | |
module D | |
end | |
class A | |
include C, D | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment