Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在运行时,如何检查模块或类从何处加载?_Ruby On Rails_Ruby_Ruby On Rails 3.1_Irb_Pry - Fatal编程技术网

Ruby on rails 在运行时,如何检查模块或类从何处加载?

Ruby on rails 在运行时,如何检查模块或类从何处加载?,ruby-on-rails,ruby,ruby-on-rails-3.1,irb,pry,Ruby On Rails,Ruby,Ruby On Rails 3.1,Irb,Pry,我有一个遗留的rails应用程序,在全局名称空间中有许多有趣的(无用的)模块和类。我想知道使用rails c需要哪些文件或gem 我知道它存在于方法:.source\u location、\uuuuuu line\uuuuuuu、\uuuuuu file\uuuuuuu和调用者对象中,但它似乎与确定类或模块的起源无关 有什么想法吗?谢谢 使用: Ruby 1.9.2 窥探 轨道3.1.1 与其说是一个真正的解决方案,不如说是一个变通办法(您要求提供一种方法),但我建议您使用。如果Rdoc/Ri

我有一个遗留的rails应用程序,在全局名称空间中有许多有趣的(无用的)模块和类。我想知道使用
rails c
需要哪些文件或gem

我知道它存在于方法:
.source\u location
\uuuuuu line\uuuuuuu
\uuuuuu file\uuuuuuu
和调用者对象中,但它似乎与确定类或模块的起源无关

有什么想法吗?谢谢

使用:

  • Ruby 1.9.2
  • 窥探
  • 轨道3.1.1

    • 与其说是一个真正的解决方案,不如说是一个变通办法(您要求提供一种方法),但我建议您使用。如果Rdoc/Ri文档已正确生成,则该文档会提到源gem

      要列出国际扶轮已知的所有类别:

      ri -l
      
      要获取特定类或模块上的文档,请执行以下操作:

      ri ClassName
      
      要获取有关方法的信息,请执行以下操作:

      ri ClassName#instance_method_name
      ri ClassName#class_method_name
      
      如果您愿意,有一个名为gem的工具,可以让您在运行时检查
      ri
      doc,这将在控制台中帮助您。irb会话上的输出示例:

      >> require 'ri_for'
      => true
      >> String.desc_class
      begin RI
      String < Object
      
      ------------------------------------------------------------------------------
      Includes:
      Diff::LCS (from gem diff-lcs-1.1.3)
      
      (from gem diff-lcs-1.1.3)
      ------------------------------------------------------------------------------
      Includes Diff::LCS into String.
      
      ------------------------------------------------------------------------------
      (from gem rake-0.8.7)
      ------------------------------------------------------------------------------
      
      
      User defined methods to be added to String.
      
      ------------------------------------------------------------------------------
      Instance methods:
      
      ext
      pathmap
      pathmap_explode
      pathmap_partial
      pathmap_replace
      
      (from gem treetop-1.4.10)
      ------------------------------------------------------------------------------
      Instance methods:
      
      blank?
      column_of
      indent
      line_of
      tabto
      treetop_camelize
      
      end ri
      String
      non inherited methods:
      %, *, +, <<, <=>, ==, ===, =~, [], []=, ascii_only?, blank?, bytes, bytesize, capitalize,    capitalize!, casecmp, center, chars, chomp, chomp!, chop, chop!, chr, clear, codepoints, column_of, concat, count, crypt, delete, delete!, downcase, downcase!, dump, each_byte, each_char, each_codepoint, each_line, empty?, encode, encode!, encoding, end_with?, eql?, force_encoding, getbyte, gsub, gsub!, hash, hex, include?, indent, index, insert, inspect, intern, length, line_of, lines, ljust, lstrip, lstrip!, match, next, next!, oct, ord, partition, replace, reverse, reverse!, rindex, rjust, rpartition, rstrip, rstrip!, scan, setbyte, size, slice, slice!, split, squeeze, squeeze!, start_with?, strip, strip!, sub, sub!, succ, succ!, sum, swapcase, swapcase!, tabto, to_c, to_f, to_i, to_r, to_s, to_str, to_sym, tr, tr!, tr_s, tr_s!, treetop_camelize, unpack, upcase, upcase!, upto, valid_encoding?
      non inherited class methods:
      try_convert
      => nil
      
      >需要“ri\u for”
      =>正确
      >>String.desc_类
      开始RI
      字符串<对象
      ------------------------------------------------------------------------------
      包括:
      差异::LCS(来自gem Diff-LCS-1.1.3)
      (摘自gem diff-lcs-1.1.3)
      ------------------------------------------------------------------------------
      将Diff::LCS包含到字符串中。
      ------------------------------------------------------------------------------
      (摘自gem rake-0.8.7)
      ------------------------------------------------------------------------------
      要添加到字符串的用户定义方法。
      ------------------------------------------------------------------------------
      实例方法:
      提取
      路径图
      路径图\u爆炸
      部分路径映射
      路径图\u替换
      (摘自gem treetop-1.4.10)
      ------------------------------------------------------------------------------
      实例方法:
      空白?
      第u列
      缩进
      第二行
      塔布托
      树顶驼峰
      结束ri
      一串
      非继承方法:
      
      %,*,+,对于类/模块,您无法直接找到这一点,但是如果您查看在类/模块上定义的方法,您可以找到它们的定义位置——通过代理,也就是定义类/模块的位置

      在中,您可以:

      [3] (pry) main: 0> stat Set#initialize
      Method Information:
      --
      Name: initialize
      Owner: Set
      Visibility: private
      Type: Unbound
      Arity: -1
      Method Signature: initialize(enum=?, &block)
      Source Location: /Users/john/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/set.rb:67
      

      查看上面的最后一项。

      他已经在使用Pry,它具有
      ri_的所有功能,用于
      gem,然后是一些。