草庐IT

using-uivisualeffectview-in-a-mod

全部标签

ruby :关键字 "in"是什么意思

当我第一次在ruby​​中找到关键字“in”时。我想也许我可以这样做:1英寸(0..10)但看起来我不能那样使用它。然后我在ruby​​-lang.org中搜索它,然后用谷歌搜索它。没有答案!ruby中关键字“in”的含义是什么? 最佳答案 您应该能够执行以下操作:foriin0..10doputsiend您提到的表达式1in(0..10)将不起作用,因为常量(1)不能在一定范围内变化-它是一个常量!您需要在in关键字之前命名一个变量。希望对您有所帮助。参见thispage 关于ruby

ruby - 为什么 inspect for the subclasses of built-in classes 中没有列出实例变量?

当我对内置类进行子类化时,为什么inspect中的行为会发生变化。但是当我子类化一个自定义的时没有看到。classMainErrorendclassAnotherTestErrort=TestError.newputst.inspect#output:# 最佳答案 因为很多(大多数?全部?)内置类是用C语言编写的,并且覆盖#inspect。例如,Exception(StandardError的父类(superclass))定义#inspect如下:exc_inspect(VALUEexc){VALUEstr,klass;klass=

ruby-on-rails - 目录 : Forgot Password & Sign In - in same page

我正在尝试将忘记密码字段与登录页面放在一起,但如果用户未注册(并且不在应用程序数据库中),则它会重定向到原始设计的忘记密码页面并出现错误(http://localhost:3000/用户/密码)。如何使错误出现在与登录页面(http://localhost:3000/users/sign_in)相同的页面中?在app/views/devise/sessions/new.html.erb文件中ForgotPasswordEntertheemailyousignedupwith所以有一个javascript链接,如果用户忘记了他们的登录凭据,输入字段将显示在该链接上。

ruby - MiniTest 的 assert_in_delta 和 assert_in_epsilon 方法有什么区别?

这里是documentationforassert_in_delta:assert_in_delta(exp,act,delta=0.001,msg=nil)publicForcomparingFloats.Failsunlessexpandactarewithindeltaofeachother.assert_in_deltaMath::PI,(22.0/7.0),0.01这里是documentationforassert_in_epsilonassert_in_epsilon(a,b,epsilon=0.001,msg=nil)publicForcomparingFloats.Fa

ruby - 名称错误 : undefined - have parsing rules for local variables changed in Ruby 2. 1.2?

我得到NameError:undefinedlocalvariableormethodwithruby​​2.1.2正如在thisquestion中观察到的那样,表达式如:barifbar=true引发未定义的局部变量错误(前提是bar之前未定义),因为bar在分配之前被解析器读取。而且我相信以前用这个表达式没有什么区别:barifbar=false两者之间的区别在于主体是否被求值,但如果遇到未定义的局部变量会在求值条件之前立即引发错误,那应该无关紧要。但是当我在Ruby2.1.2上运行第二个代码时,它没有引发错误。以前也是这样吗?如果是这样,那么解析讨论的内容是什么?如果没有,Rub

ruby - Sinatra 应用程序中的错误 "undefined local variable or method ` logger '"when using ` logger.info`

我有以下Sinatra1.2.1应用程序代码:#app.rbrequire'sinatra'get'/'dologger.info"COUCOU"'Helloworld!'end并使用ruby-rubygemsapp.rb启动服务器。当我转到http://localhost:4567时出现错误:NameErrorat/undefinedlocalvariableormethod`logger'for#file:app.rblocation:blockinline:4我是否需要添加或配置一些东西才能在Sinatra中启用日志记录?阅读SinatraREADME和文档,似乎默认情况下为Si

ruby-on-rails - rails : render a collection of models using an specific html view

我有以下关于rails的简单问题。假设我有一个模型用户。在View中,如果我这样做:views/user/_user.html.erb中的文件View将为每个用户调用和打印。如何更改它以使用特定View?我需要这样的东西:User.all:template=>"user/_user_2ndview.html"%>有什么帮助吗?提前致谢 最佳答案 您可以使用collection选项:User.all,:partial=>"users/user2ndview",:as=>:user%>View必须放在views/users/_user2

ruby - 如何修复此错误 : kernel_require. rb :45:in `require' : cannot load such file?

我有以下文件结构:执行.rb图书馆我的类(class).rb在execute.rb我有下面的代码:#!/usr/bin/rubyrequire'lib/my_class'my_object=MyClass.newmy_object.some_method这是my_class.rb的代码:classMyClassdefsome_methodputs'OK'endend所以,我尝试运行execute.rb:rubyexecute.rb但是我收到这个错误:/home/vagrant/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/ru

ruby - 在 ruby​​ 中杀死一个名为 using open3 的进程

我正在使用命令行程序,它的工作原理如下:$ROUTE_TO_FOLDER/app如果“longtext”是使用“app”需要的参数编写的,那么它将用结果填充一个文本文件。如果没有,它将连续用点填充文本文件(为了避免这种情况,我无法处理或修改“app”的代码)。在ruby​​脚本中有这样一行:text="longtextthatwillbeusedbyapp"output=system("ROUTE_TO_FOLDER/app现在,如果文本写得好,就不会有问题,我会得到一个输出文件,如前所述。当文本写得不好时,问题就来了。接下来发生的是我的ruby​​脚本挂起,我不确定如何终止它。我找到

ruby-on-rails - Aws::S3::Presigner undefined method credentials for nil:NilClass in Ruby

我使用了aws-sdk-coregem我在从aws获取url时遇到错误以下是我的代码definitialize(bucket:,region:)@bucket=bucketclient=Aws::S3::Client.new(region:region)@signer=Aws::S3::Presigner.new(client:client)enddefsign(key,expires_in:3600)@signer.presigned_url(:get_object,bucket:@bucket,key:key,expires_in:expires_in)end我遇到了错误NoMet