Find the source of gem method

How do you find the source and docs for a core method in Rails?

Slow, inaccurate way to find Rails source code

Suppose you want the source and docs for Rails Active Record cache_version. Do you search on Google or Github?

That’s the slow and inaccurate way to find Rails source code.

Why is that slow and inaccurate?

You will probably find many search results that don’t point to the right version that you’re using.

Fast, perfect way: Use Pry

Start rails console.

Note, I’m using temp var “rest” to mean “restaurant” model instance.

# Get an instance, use temp var "rest"
> rest = MyModel.first

# show source
> $ rest.cache_version

# Even better, see in your editor
> edit rest.cache_version

# See docs
> ? rest.cache_version

$ is an alias for show-source
? is an alias for show-source -d

Console Session

Opening in RubyMine

1 Like

my vim way :slight_smile:
after pressing a shortcut key on is_a?