草庐IT

java - 从共享首选项获取值时出现空指针异常

全部标签

ruby-on-rails - 运行 Heckle 时出错? `current_code' : undefined method `translate' for Ruby2Ruby

我正在尝试运行Heckle,但一直出现错误:>specspec/controllers/my_controller_spec.rb--heckleMyController!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!exception=hasathickskin.There'snothingtoheckle.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(Runsthroughseveralmu

ruby - 你如何断言另一个 ruby​​ 模块的异常被抛出? (使用 assert_throws)

我正在尝试编写这样的代码:assert_throws(:ExtractionFailed){unit.extract_from('5x2005')}ExtractionFailed是Exception的一个简单子(monad)类,在test/unit下,我试图断言它在我调用unit.extract_from(...坏数据...)我已经将ExtractionFailed移动到SemanticText模块中,所以现在test/unit说:expectedtobethrownbutwasthrown.我尝试编写assert_throws(:SemanticText::ExtractionFa

ruby-on-rails - 在 Windows 7 64 位上运行 gem 安装时出错

我刚刚使用ruby​​installer.org的安装程序安装了ruby​​1.9.2-p136,现在我正在尝试安装rails。当我执行“geminstallrails”时,出现以下错误:C:\Users\Clayton.USA>geminstallrailsERROR:Whileexecutinggem...(Errno::EINVAL)Invalidargument-P:/这是我正在运行的ruby​​和gem版本:C:\Users\Clayton.USA>ruby-vruby1.9.2p136(2010-12-25)[i386-mingw32]C:\Users\Clayton.US

ruby-on-rails - 在 Windows 7 x64 上安装 Ruby and Rails 和 DevKit 时出现问题 - 需要修复

我在尝试安装ruby​​和rails时遇到了很多问题。在清除以前安装的版本之后,我已经尝试过没有和现在。尝试运行“geminstallrdiscount--platform=ruby”时出现以下错误:C:\Windows\system32>geminstallrdiscount--platform=rubyTemporarilyenhancingPATHtoincludeDevKit...Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingrdiscount:ERROR:Failedtobuildgem

ruby-on-rails - 启动 Rails 服务器时出错 - 获取 "uninitialized constant Devise::Models::Invitable (NameError)"

我是Rails的新手,正在尝试按照这个预启动注册教程进行操作-http://railsapps.github.com/tutorial-rails-prelaunch-signup.html使用$railss初始化rails服务器时,我收到以下错误消息:Users/pv/.rvm/gems/ruby-1.9.3-p194@rails326/gems/devise-2.1.2/lib/devise/models.rb:97:in`const_get':未初始化常量设计::模型::邀请(NameError)后面跟着一堆文件路径,比如:from/Users/patrickvihtelic/.

ruby-on-rails - 使用自定义异常时未初始化的常量

我正在尝试为我的应用创建自定义异常(exception)。我的libs文件夹中有一个示例库,其文件夹结构如下:-lib/||--social/||--bandcamp.rb这个bandcamp.rb文件内容如下:moduleSocialclassExampleException问题是,我可以在我的应用程序中的任何地方使用Social::Bandcamp.new.some_method,它工作得很好,但我无法访问Social::ExampleException也不会在任何地方提出。它给了我NameError:uninitializedconstantSocial::ExampleExce

ruby - 使用 progressbar/ruby-progressbar gem 时出现 Zlib::BufError

我使用以下Ruby片段下载a8.9MBfile.require'open-uri'require'net/http'require'uri'defhttp_download_no_progress_bar(uri,filename)uri.open(read_timeout:500)do|file|openfilename,'w'do|io|file.each_linedo|line|io.writelineendendendend我想添加progressbargem可视化下载过程:require'open-uri'require'progressbar'require'net/htt

ruby - 在 Heroku 中的 Puma 上部署 Rails 应用程序时出错

我正在尝试部署在Puma和jruby上运行的Rails应用程序。Procfile如下web:bundleexecpuma-Cconfig/puma.rb-p$PORT-e$RACK_ENVPuma的配置放在config/puma.rbifENV['RACK_ENV']!='production'||ENV['RAILS_ENV']!='production'workersInteger(ENV['PUMA_WORKERS']||4)endthreadsInteger(ENV['MIN_THREADS']||1),Integer(ENV['MAX_THREADS']||4)rackupD

ruby - 为什么 Ruby 在抛出 NameError 异常后仍保留代码求值?

我无法向自己解释的简单代码:putsaifa=1这导致warning:found=inconditional,shouldbe==NameError:undefinedlocalvariableormethod'a'formain:Object不过,现在检查a我们可以看到,它已被定义:a#=>1尽管抛出异常,为什么a仍被分配给1?来自docs:Theconfusioncomesfromtheout-of-orderexecutionoftheexpression.Firstthelocalvariableisassigned-tothenyouattempttocallanonexis

ruby - 在 Ruby 中获取调用者的模块

我们有代码在我们的Ruby1.8.6网络应用程序中记录数据。你大致这样调用它:$log.info("Sometexthere")现在,在记录的输出中,我想包括该行出现的模块。我知道Kernel#caller会给我一个数组,我可以在其中提取日志行出现的文件和行号,但我不希望这样。我想要模块,而不是文件名。显而易见的解决方案是修改日志行,使其如下所示:$log.info("Sometexthere",self.class.name)然后解析结果。不过,这行不通,因为我试图在默认情况下提取此信息。也就是说,如果程序员忘记指定模块(日志行的第二个参数),我需要解决方案。有什么办法吗?如果没有,