草庐IT

Constant

全部标签

ruby-on-rails - 名称错误 : uninitialized constant on Heroku

我有一个Rails5应用程序,其中一些模块/类位于/lib下。在开发中,我可以像这样通过Rails控制台访问它们:irb(main):001:0>MyClass.do_something在Heroku的生产环境中,我得到了这个:irb(main):001:0>MyClass.do_somethingNameError:uninitializedconstantMyClass您可能已经猜到了,我在我的application.rb中自动加载了/lib目录:config.autoload_paths然而,最奇怪的是,我可以从rake任务访问这个类。所以像这样的东西很好用:taskdo_som

ruby - 如何摆脱 ruby​​ 的警告 : already initialized constant

我正在尝试动态地重新定义gem的常量,因此我不需要修改gem本身。require'xmlrpc/client'XMLRPC::Config.const_set("ENABLE_NIL_PARSER",true)warning:alreadyinitializedconstantENABLE_NIL_PARSER是否可以消除警告? 最佳答案 简单的方法:v,$VERBOSE=$VERBOSE,nil#codegoeshere$VERBOSE=v 关于ruby-如何摆脱ruby​​的警告:a

ruby-on-rails - Google API Ruby 客户端(gem)错误 `uninitialized constant Google::APIClient::UploadIO`

这肯定让我困惑了几个小时。我有bootstrappedmyapplicationasdetailedbyBaugues到通过OAuth2进行身份验证有效的程度,我只是在session#create(回调)操作中进行测试。这是一些代码:classSessionsControllerservice.files.get,#:parameters=>{'id'=>1},#:headers=>{'Content-Type'=>'application/json'})endend身份验证后,上述逻辑在callback方法中执行-出于此粗略测试的目的,它呈现出create.html.erb。我已经注

ruby - sidekiq+whenever+unicorn uninitialized constant ClassWorker 生产环境

我使用Rails4,sidekiq2.13.1,cron脚本每2分钟运行一次。第一次执行期间没有错误,但接下来的所有错误。我只在生产环境中遇到这个错误。我的worker位于app/workers中。我在application.rb中通过以下字符串将其包含在内:config.eager_load_paths+=%W(#{config.root}/app/workers)错误:2013-08-15T12:34:05Z31102TID-oh1d0WARN:{"retry"=>true,"queue"=>"default","class"=>"AllGlobalWorker","args"=>

ruby - 使用 gchart (googlecharts) gem 时出错 - NameError : uninitialized constant Gchart

http://googlecharts.rubyforge.org/我安装了它:sudogem安装googlecharts它安装得很好,但每当我尝试使用它时,我都会得到:NameError:未初始化常量Gchart这是我正在运行的代码:$irb>>require'gchart'=>true>>Gchart.line(:data=>[0,40,10,70,20])NameError:uninitializedconstantGchartfrom(irb):2 最佳答案 Kale,我也有这个问题。还有另一个名为gchart的gem与go

ruby-on-rails - gem 未加载 : NameError (uninitialized constant) | But gem works in local path

我买了一台新机器并全新安装了rbenv(我之前一直使用rvm)。Thisgem现在不会加载到我的应用程序中。我没有做任何代码更改。现在和那时的唯一区别是rbenv。Loadingdevelopmentenvironment(Rails5.2.1)irb(main):001:0>SportsApi::Fetcher::Score::NBATraceback(mostrecentcalllast):1:from(irb):1NameError(uninitializedconstantSportsApi::Fetcher)有趣的是,如果我将gem克隆到我的本地机器,然后更改Gemfile中

ruby - Chefspec 重复加载库并发出警告 "already initialized constant CONSTANT"

我有一本带图书馆的ChefRecipe,例如库.rb。它包含一个CONSTANT:CONSTANT='constant'当我为这本Recipe编写单元测试时,它总是给我警告:(Someprefix...)warning:alreadyinitializedconstantCONSTANT(Someprefix...)warning:previousdefinitionofCONSTANTwashere警告反复出现,次数为示例(测试用例)减一。我认为这是因为chefspec为每个示例加载一次库。谁能告诉我如何让库只加载一次,或者如何禁用警告消息? 最佳答案

go - 常量无类型是什么意思?

GoProgrammingLanguageSpecification说:Constantsmaybetypedoruntyped我对自己的理解有点怀疑。考虑一下规范中的这个例子:constl="hi"//l=="hi"(untypedstringconstant)constm=string(k)//m=="x"(typestring)规范说:constantmaybegivenatypeexplicitlybyaconstantdeclarationorconversion,orimplicitlywhenusedinavariabledeclarationoranassignment

go - 常量无类型是什么意思?

GoProgrammingLanguageSpecification说:Constantsmaybetypedoruntyped我对自己的理解有点怀疑。考虑一下规范中的这个例子:constl="hi"//l=="hi"(untypedstringconstant)constm=string(k)//m=="x"(typestring)规范说:constantmaybegivenatypeexplicitlybyaconstantdeclarationorconversion,orimplicitlywhenusedinavariabledeclarationoranassignment

dictionary - 为什么 Golang 不允许 const 映射?

我想创建一个如下所示的常量映射:const(running=map[string]string{"one":"ONE","two":"TWO",})但是每当我这样做时,我都会收到以下错误:constinitializermap[string]字符串字面量不是常量为什么会这样,为什么Golang不像其他变量一样对待它们? 最佳答案 来自https://golang.org/ref/spec#Constants:Aconstantvalueisrepresentedbyarune,integer,floating-point,imagi