簡體   English   中英

為什么 Rails 執行器無法識別 Kernel 上的改進?

[英]Why does the Rails executor not recognize refinements on Kernel?

我發現如果代碼在Rails 執行器中運行,則無法識別改進。 這似乎不是因為塊或過程,這是我唯一的猜測。 這是一些演示代碼:

require './config/environment.rb'

module ExammpleRefinement
  refine ::Kernel do
    def say_hello
      puts "hello"
    end
  end
end

using ExammpleRefinement

puts "alone"
say_hello
puts "block"
loop do
  say_hello
  break
end
puts "proc"
Proc.new{say_hello}.call

puts "rails executor"

::Rails.application.executor.wrap do
  say_hello
end

ruby example.rb運行(不能用rails runner來做,因為從 rails 7 開始它把整個腳本包裝在一個執行器中,所以它破壞了實驗)

alone
hello
block
hello
proc
hello
rails executor
Traceback (most recent call last):
    2: from example.rb:25:in `<main>'
    1: from ....rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/activesupport-7.0.4/lib/active_support/execution_wrapper.rb:92:in `wrap'
scripts/example.rb:26:in `block in <main>': undefined local variable or method `say_hello' for main:Object (NameError)

ruby 2.7

我無法使用您提供的確切測試文件重現該行為(在我的測試中,它在需要config/environment后立即失敗,無論執行程序包裝如何),但我想我已經將其跟蹤到相同的原因:

在應用程序初始化期間,可能是由於使用了 EventedFileUpdateChecker, Kernel 被 ForkTracker 前置

大概(並且有點可以理解),改進不喜歡那樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM