草庐IT

end-of-file

全部标签

ruby - 获取 `initialize' : wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app

这是我的第一个ruby应用程序。我是一个堆栈溢出处女......当我运行以下程序时:classNameAppdefintialize(name)@names=[]enddefname_questionprint"Whatisyourname?"answer=gets.chomp@names+=answer.to_sputs"Thenumberofcharactersinyournameis"+names.lengthenddefname_lengthif@names.length>25thenprint"Yournameislongerthan25characters."elsepri

ruby - kernel_require.rb :55:in `require' : cannot load such file error

我目前使用的是Ruby1.9.3版(尽管我在使用Ruby2.0.0时遇到了同样的问题)。在Windows764位上。我正在关注“TheCucumberBook”并卡在第7.2章-“使用转换删除重复项”。我的文件夹结构如下:\cash_withdrawal\cash_withdrawal\Gemfile\cash_withdrawal\Gemfile.lock\cash_withdrawal\features\cash_withdrawal\features\cash-withdrawal.feature\cash_withdrawal\features\step_definitions

ruby - Homebrew 软件 - 错误的解释器 : No such file or directory

像个白痴一样,我设法删除了我的系统ruby​​安装。我重新安装了xcode,还安装了RVM这样做:$whichruby返回这个:/Users/alex/.rvm/bin/ruby但是,Homebrew似乎还是坏了:$brew-bash:/usr/local/bin/brew:/usr/bin/ruby:badinterpreter:Nosuchfileordirectory 最佳答案 OSX上的系统ruby​​符号链接(symboliclink)到Ruby.framework。由于您重新安装了Xcode,它应该已安装,但您需要恢复符

ruby-on-rails - "require File.expand_path(' ../../config/environment', __FILE__)"到底做什么?

我一直在尝试更深入地了解Ruby,解构样板式rails应用程序似乎是了解编写跨不同文件和目录的Ruby应用程序的一些细节和优雅的好方法。在我当前的应用程序中,文件之间对“requires”的依赖变得有点问题(我发现我需要做一些事情,比如requires'../../../lib/helper'它变得有点丑陋。我注意到Rails应用程序似乎不受此影响。我确实注意到了这条线:requireFile.expand_path('../../config/environment',__FILE__)当我用谷歌搜索时,我发现很多关于Rails启动例程等的解释,但没有关于该行到底做什么的明确描述。在

ruby - 如何避免使用 allow_any_instance_of?

假设我们有以下代码:classAdefcreate_serveroptions={name:NameBuilder.new.build_name}do_some_operations(options)endend为了测试这些方法,我曾经使用allow_any_instance_of:it'doesoperations'doallow_any_instance_of(NameBuilder).toreceive(:build_name)#testbodyend但是文档建议我们不要使用它becauseofseveralreasons.那么如何避免allow_any_instance_of呢

ruby-on-rails - 弃用警告 : Object#returning has been deprecated in favor of Object#tap

如何更改以下方法以使用tap来停止像这样的警告弃用警告:Object#returning已被弃用,取而代之的是Object#tap。(从/Users/millisami/apps/pandahr/config/initializers/fix_active_model_full_message.rb:17的full_messages调用):ActiveModel::Errors.class_evaldo#Removecomplicatedlogicdeffull_messagesreturningfull_messages=[]doself.each_keydo|attr|self[a

ruby-on-rails - rails ActiveAdmin : showing table of a related resource in the same view

当使用RailsActiveAdmingem显示资源时,我想显示另一个关联模型的表格。假设一个酿酒厂有很多:products。现在我想在Winery管理资源的show页面上显示关联的产品。我希望它是一个类似于我在Products资源的index上得到的表格。我让它工作了,但只能通过手动重新创建HTML结构,这很糟糕。是否有更简洁的方法来为关联资源的特定子集创建index表样式View?我有什么,有点糟透了:showtitle::namedo|winery|attributes_tabledorow:namerow(:region){|o|o.region.name}rows:prima

ruby-on-rails - Rails 控制台 : Run a Ruby file several times

Rails提供了一个非常有用的控制台('script/console')。我编写了一个ruby​​文件并使用requirefoo.rb在控制台中运行它。第一次工作正常,但第二次和下一次requirefoo.rb没有运行我的脚本(require没有重新加载它)。你有什么提示/技巧吗? 最佳答案 require用于加载扩展-因此代码将执行一次,以使扩展出现在您的环境中,但随后的require不会做任何事情,因为工作已经完成完成。load,另一方面,每次加载并执行代码。如前所述,如果你只是想运行你的脚本并且你需要Rails环境,那么可以考

ruby - 命名约定 : Why Array#delete has no exclamation mark at the end?

我正在学习Ruby,我发现按照惯例,方法名称末尾的感叹号表示该方法以某种方式修改了self。为什么Array#delete不像slice!那样以感叹号结尾,因为delete从self中删除一个元素?我错过了一些基本的东西吗? 最佳答案 引用Matz(Ruby的总工程师):Thebang(!)doesnotmean"destructive"norlackofitmeannondestructiveeither.Thebangsignmeans"thebangversionismoredangerousthanitsnonbangcou

ruby-on-rails - Rails 控制台 : in `require' : cannot load such file -- readline (LoadError)

我的Rails应用程序出现一些错误,我正在尝试通过发出以下命令来启动Rails控制台:railsconsole无论我尝试什么,我总是得到同样的错误:/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in`require':cannotloadsuchfile--readline(LoadError)from/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in`'from/opt/mammie/web/icosole