草庐IT

autoloading

全部标签

ruby - 使用 autoload 与 ruby​​ 中的 require 进行惰性评估?

在我的代码中,我使用自动加载进行惰性评估,这样我可以更快地加载程序并在需要时加载文件,我没有看到很多人使用它,但在Thin项目中我注意到自动加载已被广泛使用,反正只是想知道使用它是否有任何风险。 最佳答案 autoload是notthreadsafe并将在未来的Ruby版本中弃用。这是proofbyMatz(ruby的创造者)。 关于ruby-使用autoload与ruby​​中的require进行惰性评估?,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails - rails 5 : Autoloading with custom folders not working

我有这门课:#app/events/new_request.rbclassEvents::NewRequestend然后我将该文件夹添加到自动加载:#config/application.rbconfig.autoload_paths+=%W(events/)当运行railsc时:>Events::NewRequestNameError:uninitializedconstantEvents问题是,如果我在定义类时不使用命名空间“Events”,它会成功自动加载类。 最佳答案 moduleSandboxclassApplicatio

ruby-on-rails - 命名空间模块和 Rails 3.1.3 autoload_path

我在为包含在模型中的模块命名空间时遇到了一些麻烦。在/app/models/car.rb中classCarincludeSearch::Carend在/lib/search/car.rb中moduleSearchmoduleCarincludeActiveSupport::Concern#methodsinhereendend在/config/application.rb中config.autoload_paths+=Dir["#{config.root}/lib/**/"]config.autoload_paths+=Dir["#{config.root}/lib/search/*"

ruby - 运行时错误 : Circular dependency detected while autoloading constant

我通过引入请求和响应模型来重构我的Controller,以执行此presentation之后Controller周围的一些逻辑。.我分别用模块Responses和Requests包装了所有的响应和请求模型。应用程序运行完美,但当我运行测试时,出现以下错误。Failure/Error:UnabletofindmatchinglinefrombacktraceRuntimeError:CirculardependencydetectedwhileautoloadingconstantResponses::FolderContentResponse我的目录结构如下:-应用/-模型/-回应/注

ruby-on-rails - Controller : Circular dependency detected while autoloading constant 中的 Rails 4 运行时错误

如果我遗漏了什么,请告诉我。我不明白为什么无法访问我的views/references/文件夹。new.html.erb和index.html.erb都不可用。当我转到localhost:3000/references时,我的错误是:RuntimeErrorinReferencesController#indexCirculardependencydetectedwhileautoloadingconstantReferencesController我相信这是设置,它不应该是Rails问题,因为我的其他Controller工作正常。我的路线文件中有resources:reference

ruby-on-rails - 为什么都是autoload,load_all!并要求全部用于 active_support.rb?

我正在查看active_support.rb以尝试了解它使用的加载过程。它使用三种加载方法:load_all!、autoload和require。为什么在同一个文件中使用三种不同的加载方式?moduleActiveSupportdefself.load_all![Dependencies,Deprecation,Gzip,MessageVerifier,Multibyte,SecureRandom,TimeWithZone]endautoload:BacktraceCleaner,'active_support/backtrace_cleaner'autoload:Base64,'ac

ruby-on-rails - Rails 中的多线程 : Circular dependency detected while autoloading constant

我有一个Rails应用程序,其中有一个Rake任务,该任务使用并发rubygem提供的多线程函数。有时我会遇到Circulardependencydetectedwhileautoloadingconstant错误。在谷歌搜索了一下后,我发现这与结合使用线程和加载Rails常量有关。我偶然发现了以下GitHub问题:https://github.com/ruby-concurrency/concurrent-ruby/issues/585和https://github.com/rails/rails/issues/26847如此处所述,您需要将从新线程调用的所有代码包装在Rails.a

ruby - 随着 'autoload' 被弃用,开发者应该同时使用什么?

几周前读到autoload是officiallydeprecated,Matz不鼓励使用它。用什么来代替它?开发人员应该怎么做?我在一些命令行gem中使用它来避免不必要地加载可能永远不会使用的库,并在JRuby中使用它来防止对.jar文件进行相同的加载。 最佳答案 我见过人们使用EasyLoadgem,它声称是一个autoload替代品。它根据目录模块命名约定加载。 关于ruby-随着'autoload'被弃用,开发者应该同时使用什么?,我们在StackOverflow上找到一个类似的问

ruby-on-rails - 为什么我使用 Rails 和 grape 得到 "Unable to autoload constant"?

我想为Android应用做一个API。搜索时,我找到了{grape}.我正在关注thistutorial,但我在启动Rails服务器时遇到问题:=>BootingWEBrick=>Rails4.0.2applicationstartingindevelopmentonhttp://0.0.0.0:80=>Run`railsserver-h`formorestartupoptions=>Ctrl-CtoshutdownserverExitingC:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/

ruby - 在没有 `autoload` 的情况下在 Ruby 中自动加载类

我爱theautoloadfunctionalityofRuby;然而,它是goingawayinfutureversionsofRuby因为它从来都不是线程安全的。所以现在我想假装它已经消失并在没有它的情况下编写我的代码,方法是自己实现延迟加载机制。我想以最简单的方式实现它(我现在不关心线程安全)。Ruby应该允许我们这样做。让我们从扩充一个类开始const_missing:classDummydefself.const_missing(const)puts"const_missing(#{const.inspect})"super(const)endend当我们尝试引用“Dummy