Created
December 16, 2014 05:10
-
-
Save balramkhichar/1928b36c7b81cbea76c0 to your computer and use it in GitHub Desktop.
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
def location_in_hierarchy(object, method) | |
history = [] | |
current = object.class | |
history << current | |
while (current.superclass!=nil) | |
history << current.superclass | |
current = current.superclass | |
end | |
history = history.reverse | |
history.find do |ob| | |
ob.instance_methods.include?(method) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good effort.
Try to write idomatic ruby code. This you will learn with experience.
You are running a lot of loops. When you write code, try to get the job done with minimal effort. Each loop is a load on your CPU. If you application needs to scale, you need to optimize every frickin line.
Good effort though :)