Reputation: 8105
If I have a class in Ruby and a Gemfile thousand lines long, what's the best way to resolve the class => gem
relationship?
Upvotes: 0
Views: 43
Reputation: 28305
Having a Gemfile
that's 1000 lines long is probably going to be a big source of pain, especially when upgrading libraries - that's a huge list of dependencies!!
It's often obvious which gem is the source, just by looking at the naming conventions. But in cases when not, you can track it down with Method#source_location
:
> puts method(:mystery_method).source_location
> puts MysteryClass.method(:initialize).source_location
If you are using pry
, then there is also a convenient command for displaying the source code of a class/method (using the show-method
command, or $
for short):
(pry) > $ mystery_method
(pry) > $ MysteryClass
Also worth mentioning is Method#super_method
- which can be useful when tracking down behaviour from complex inheritance/mixins.
Upvotes: 1