Skip to content

Instantly share code, notes, and snippets.

@balramkhichar
Created December 16, 2014 05:10
Show Gist options
  • Save balramkhichar/1928b36c7b81cbea76c0 to your computer and use it in GitHub Desktop.
Save balramkhichar/1928b36c7b81cbea76c0 to your computer and use it in GitHub Desktop.
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
@aalavandhan
Copy link

Good effort.

Try to write idomatic ruby code. This you will learn with experience.

#Insted of doing this
current.superclass!=nil
#Do this - More readable
current.superclass.present?

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment