Created
September 20, 2013 11:06
-
-
Save tobiashm/6636001 to your computer and use it in GitHub Desktop.
Example of how to determine if a class method is defined on the current class or an ancestor. Notice that Method#owner returns the metaclass, so we can't just compare to the class itself.
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
base_classes_with_own_connection = ActiveRecord::Base.subclasses.find_all { |klass| | |
klass.method(:establish_connection).owner == (class << klass; self; end) | |
} | |
([ActiveRecord::Base] + base_classes_with_own_connection).each do |base| | |
base.establish_connection | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative predicate: