Skip to content

Instantly share code, notes, and snippets.

@guilhermesilveira
Created March 25, 2011 16:00
Show Gist options
  • Save guilhermesilveira/887082 to your computer and use it in GitHub Desktop.
Save guilhermesilveira/887082 to your computer and use it in GitHub Desktop.
checking for coupling and encapsulation fails
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
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