Ruby工具来浏览已安装的宝石代码 [英] Ruby tool to browse through installed gems code

查看:79
本文介绍了Ruby工具来浏览已安装的宝石代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



目前为了了解它是如何工作的,我必须去github,搜索gem意识到代码来自于依赖关系,搜索其他gem的代码repo,意识到这是另一个gem,找到它,找到类,然后从一个类到另一个类,并打开很多浏览器选项卡。 / p>

我在Linux上使用崇高文本。是否有一些工具可以让我直接从gem中访问代码?

你可以使用 pry with 源代码浏览。



这是一个类似于IRB的控制台,您可以查看写入的任何类/方法的定义简单的Ruby。



下面是一个例子 rgeo gem:

 > pry 
[1] pry(main)>需要'rgeo'
=> true
[2] pry(main)> show-source RGeo :: Cartesian.factory

From:〜/ .rvm / gems / ruby​​-2.3.1 / gems / rgeo-0.6.0 / lib / rgeo / cartesian / interface.rb @第27行:
所有者:#< Class:RGeo :: Cartesian>
可见性:public
行数:7
$ b $ def preferred_factory(opts_ = {})
if :: RGeo :: Geos.supported?
:: RGeo :: Geos.factory(opts_)
else
simple_factory(opts_)
end
end


I am using a gem and I have trouble figuring out how to use a specific method.

Currently to understand how it works, I have to go to github, search the gem realise the code is from a dependency, search the code repo for the other gem, realise it's another gem, locate it, find the class, and from there go from one class to another with a lot of browsers tabs open.

I am on Linux using sublime text. Is there some tool that would allow me to directly access the code from a gem ?

解决方案

You could use pry with source-browsing.

It's a console similar to IRB, and you can view the definition of any class/method that is written in plain Ruby.

Here's an example with rgeo gem :

> pry                                                                                                               
[1] pry(main)> require 'rgeo'
=> true
[2] pry(main)> show-source RGeo::Cartesian.factory

From: ~/.rvm/gems/ruby-2.3.1/gems/rgeo-0.6.0/lib/rgeo/cartesian/interface.rb @ line 27:
Owner: #<Class:RGeo::Cartesian>
Visibility: public
Number of lines: 7

def preferred_factory(opts_ = {})
  if ::RGeo::Geos.supported?
    ::RGeo::Geos.factory(opts_)
  else
    simple_factory(opts_)
  end
end

这篇关于Ruby工具来浏览已安装的宝石代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆