jjzjj

argument-passing

全部标签

ruby - "wrong number of arguments"使用圆形时出现 ArgumentError

我正在尝试将温度从华氏度转换为摄氏度:puts'ConvertirgradosFahrenheitaCelcius'STDOUT.flushx=gets.chompaprox=(x*100.0).round(2)/100.0resultado=(aprox-32)/1.8putsresultado我使用正确的公式将华氏度转换为摄氏度:Celsius=Fahrenheit-32/1.8但是,当我在控制台中运行它时,出现以下错误:`round':wrongnumberofarguments(1for0)(ArgumentError)我尝试过不同的方法,但我不明白为什么这不起作用。

ruby - Jekyll 服务 "Error: Invalid argument"问题

我目前正在运行在我的Windows7PC上本地安装和生成Jekyll站点的阶段。我已经安装了所有要求并且可以让Jekyll启动,但我无法让它提供服务。每当我尝试时,它都会返回以下错误:$jekyllserve-tConfigurationfile:c:/wamp/www/ShaunYearStrong.github.io/_config.ymlSource:c:/wamp/www/ShaunYearStrong.github.ioDestination:c:/wamp/www/ShaunYearStrong.github.io/_siteGenerating...c:/Ruby193/

Ruby:自动将实例变量设置为方法参数?

是否有计划实现类似于在方法参数列表中指定实例变量名称的CoffeeScript功能的ruby​​行为?喜欢classUserdefinitialize(@name,age)#@nameissetimplicitly,but@ageisn't.#thelocalvariable"age"willbeset,justlikeitcurrentlyworks.endend我知道这个问题:inRubycanIautomaticallypopulateinstancevariablessomehowintheinitializemethod?,但所有的解决方案(包括我自己的)似乎都不符合ruby

ruby-on-rails - Form_for "First argument in form cannot contain nil or be empty"错误

我不明白为什么会收到此错误,也不知道它的确切含义。Firstargumentinformcannotcontainnilorbeempty(Line3)添加新帖子//ErrorhereController:classPostsController"Yourpostwassaved"elserender"new"endenddefeditenddefupdateenddefdestroyendend 最佳答案 假设您从PostsController渲染它并使用传统的View名称,您的new方法应该创建一个新的Post并分配给它:def

ruby-on-rails - 参数错误 : wrong number of arguments (1 for 2)

我是Rails、MVC和CRUD的新手,我正在尝试使用更新方法来更改帖子的投票数量。我的PostsController更新方法中有以下代码:defupdate@post=Post.find(params[:id])ifparams[:vote]=='up'@post.update_column(:ups=>@post[:ups]+1)elsifparams[:vote]=='down'@post.update_column(:downs=>@post[:downs]+1)endflash[:notice]="Thanksforvoting!Thishelpsusdetermineimp

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-on-rails - minitest_plugin.rb :9 getting wrong number of arguments

~/Sites/sample_app$railstestRunningviaSpringpreloaderinprocess24338Runoptions:--seed58780Running:..Finishedin0.292172s,6.8453runs/s,6.8453assertions/s./var/lib/gems/2.3.0/gems/railties-5.1.0/lib/rails/test_unit/minitest_plugin.rb:9:in`aggregated_results':wrongnumberofarguments(given1,expected0)(

ruby - 如何解决 factory_girl wrong number of arguments 错误

#rspectestcode@room=FactoryGirl.build(:room)#factorydefinitionfactory:roomdolength{10}width{20}end#codeimplementationclassRoomattr_accessor:length,:widthdefinitialize(length,width)@length=length@width=widthendend在尝试构建@room时运行rspec会导致此错误ArgumentError:wrongnumberofarguments(0for2) 最佳

ruby - 如果我不指定 <programfile>,我如何将 <arguments> 传递给 IRB?

自:irb--help用法:irb.rb[选项][程序文件][参数]我知道如果我包含一个程序文件,我可以将参数传递给ARGV例如:irbtest.rbABC其中test.irb只是“pARGV”产生:["a","b","c"]使programfile在DOS中成为con...我可以执行以下操作irbconABCcon(main):001:0>ARGV产生:ARGV=>["A","B","C"]但这是系统相关的并且有回显输入的副作用:-(我真正喜欢的是类似的东西irb--abc顺便说一句:我知道我可以在irb中设置ARGV,但我的意图是别名special==irb-rSpecialLib

ruby - 使用 ( :send) in Ruby with keyword arguments?

我有一个私有(private)方法,我正尝试在Ruby中使用#sendto进行一些测试。该方法很复杂,我不想暴露在类之外,所以我想测试该方法,但我也不需要将其列为公共(public)方法。它有关键字参数。我怎样才能使用send来调用该方法,同时还向它传递关键字参数/命名参数?有办法吗?方法如下所示:defsome_method(keyword_arg1:,keyword_arg2:,keyword_arg3:nil) 最佳答案 取决于关键字参数的定义方式。如果出于某种原因将它们定义为内联,则将它们内联传递:SomeClass.sen