gpt4 book ai didi

ruby-on-rails - 为什么pretty_print 在这个片段中不能用于分析Rails 应用程序内存?

转载 作者:行者123 更新时间:2023-12-01 06:05:20 25 4
gpt4 key购买 nike

所以我在 Railer Performance 一书中跟随它,它告诉我在 environment.rb 中制作以下代码片段:

MemoryProfiler.report do
# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!

end.pretty_print(to_file: "test.txt")

然后我应该运行 rails runner "puts 'hello world'"
但是当我这样做时,我得到:
/Users/samantha/.rbenv/versions/2.3.1/lib/ruby/2.3.0/pp.rb:316:in `pretty_print': undefined method `text' for {:to_file=>"test.txt"}:Hash (NoMethodError)
Did you mean? test

Pretty_print 是我应该安装的 ruby​​ gem 吗?

最佳答案

我想你的 MemoryProfiler.report do ... end块返回零(我不知道为什么会发生)。

当报告存在时,它会执行 MemoryProfiler 的 pretty_print MemoryProfiler::Results 实例上的方法.

当 report 为 nil 时,它执行 Ruby 的 pretty_print NilClass 实例上的方法.

关于ruby-on-rails - 为什么pretty_print 在这个片段中不能用于分析Rails 应用程序内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40774146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com