c - 如果我在Ruby中 pry Array,那么pretty_print函数从哪里来

标签 c ruby arrays pry

我在玩弄 pry ,撞到了让我困惑的东西。

irb
pry
cd Array

pry(Array):>

show-method 返回:

def pretty_print ...
def pretty_print_cycle ...

那些方法在哪里?我从 Ruby Array doc 查看了 ruby 数组并且找不到方法。我去了search for array in github ruby project看到 Array.c 但找不到 Array.rb。即使那样,我也无法在 Array.c 中找到 pretty_print。

谁能帮我理解一下?

谢谢!

最佳答案

试试这个:

[].method(:pretty_print).source_location
=> ["/home/joel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/pp.rb", 328]

似乎 show-method 给出了同样的信息:

show-method [].pretty_print

From: /home/joel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/pp.rb @ line 328:
Owner: Array
Visibility: public
Number of lines: 7

def pretty_print(q)
  q.group(1, '[', ']') {
    q.seplist(self) {|v|
      q.pp v
    }
  }
end

pry.rb 需要 pp:

https://github.com/pry/pry/blob/dd2d9b927b0afbe4e5463ff1558c566abbdb0473/lib/pry.rb

关于c - 如果我在Ruby中 pry Array,那么pretty_print函数从哪里来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24945647/

相关文章:

c - scanf() 在文件处理中不起作用?

python - np.isnan 用于 Python 中的数组

arrays - 如何在 Go 中保持强引用?

c - 如何初始化一个 3 维数组

c - 测试链表

更改 const 对象 - 没有警告?另外,在什么情况下是 UB?

c - 是否可以将两个具有不同签名的函数作为参数传递给另一个函数?

ruby-on-rails - gem 安装在包文件夹(供应商/包)

ruby-on-rails - 将范围添加到 ActiveAdmin 路由获取 ActionController::UrlGenerationError

Ruby 类实例方法 def 初始化 : instance or class method?