finding function defenition

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

finding function defenition

Ilya Makedon
How does one figure out where a definition of a function is given its call in Ruby on Rails code?  For example, let's suppose, I didn't know what config/routes.rb is for.  And I was looking at it and wanted to know what the function get does.  It's not defined in routes.rb itself.  There are no includes, requires or inheritance.  How would one know what functions named get are available in that scope and which one of them would be called at runtime?  I'm looking for a systematic way applicable to an arbitrary file in a Rails project calling arbitrary function that could be part of Rails or dependency gem.

When I tried 'Go To Definition' of the get in RubyMines, it popped up a list of about 100 options of what i could be.  Is there an IDE that's better at this than RubyMine?

As for me, I can't even come up with a search terms to get something resembling an answer on google.  That's why I humbly request your help.  thanks.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c6554db8-38f2-4782-8921-f9ecfdf18632%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

finding function defenition

San Ji
To my knowledge, what you are looking for is not possible for Ruby.

What you got in RubyMine is the closest, basically it index all words and apply some language heuristics to scope down choices. This is good enough in most cases.

Systematic way to do it is impossible because Ruby supports metaprogramming.
Take ActiveRecord as an example, you got attribute-related methods that defines in databases, not even in Ruby code. If you connect to different databases, the method definitions will be different. Nothing can even point that out (represent that) properly, at least not with user interface of an IDE.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/63fd8953-f3a8-47a9-a931-17dd2eb3cce4%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: finding function defenition

Ilya Makedon
San Ji, thank for your answer.  But how does Ruby runtime know which function to call?  There must be a way for human to mimic that...  Right?

On Sat, Mar 21, 2020 at 10:35 AM San Ji <[hidden email]> wrote:
To my knowledge, what you are looking for is not possible for Ruby.

What you got in RubyMine is the closest, basically it index all words and apply some language heuristics to scope down choices. This is good enough in most cases.

Systematic way to do it is impossible because Ruby supports metaprogramming.
Take ActiveRecord as an example, you got attribute-related methods that defines in databases, not even in Ruby code. If you connect to different databases, the method definitions will be different. Nothing can even point that out (represent that) properly, at least not with user interface of an IDE.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/63fd8953-f3a8-47a9-a931-17dd2eb3cce4%40googlegroups.com.


--
--------------------------
- Ilya Makedon

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAOJppg6O0txtYvKgXzEVaeNqM_%3D5Czofe-4vQZZCi-uYHFTaBA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: finding function defenition

Ariel Juodziukynas
One thing you can do is use a gem like byebug, put a breakpoint above the code you want to find it's location and use this:

method(:name_of_method).source_location

if you put a breakpoint inside your routes.rb and call:

method(:get).source_location

it returns something like:

...../gems/actionpack-6.0.2.2/lib/action_dispatch/routing/mapper.rb, 711

Than you can check the source on github


It doesn't always work, you can have methods generated on the fly using define_method for example I'm not sure source_location gives you the right source there.

El sáb., 21 mar. 2020 a las 17:36, Ilya Makedon (<[hidden email]>) escribió:
San Ji, thank for your answer.  But how does Ruby runtime know which function to call?  There must be a way for human to mimic that...  Right?

On Sat, Mar 21, 2020 at 10:35 AM San Ji <[hidden email]> wrote:
To my knowledge, what you are looking for is not possible for Ruby.

What you got in RubyMine is the closest, basically it index all words and apply some language heuristics to scope down choices. This is good enough in most cases.

Systematic way to do it is impossible because Ruby supports metaprogramming.
Take ActiveRecord as an example, you got attribute-related methods that defines in databases, not even in Ruby code. If you connect to different databases, the method definitions will be different. Nothing can even point that out (represent that) properly, at least not with user interface of an IDE.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/63fd8953-f3a8-47a9-a931-17dd2eb3cce4%40googlegroups.com.


--
--------------------------
- Ilya Makedon

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAOJppg6O0txtYvKgXzEVaeNqM_%3D5Czofe-4vQZZCi-uYHFTaBA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcBXi0BiPo%2BkB7nT8QdNP2orFYcg0oM95pQBDYodyUtQpA%40mail.gmail.com.