草庐IT

b-Class-Interface

全部标签

ruby - 在 define_method 中调用 super 时没有父类(super class)方法

当我重写一个已经存在的方法时,为什么会出现以下错误talk:super:nosuperclassmethodtalk(NoMethodError)?如何修复此代码以调用super方法?这是我正在使用的示例代码classFoodeftalk(who,what,where)p"#{who}is#{what}at#{where}"endendFoo.new.talk("monster","jumping","home")classFoodefine_method(:talk)do|*params|super(*params)endendFoo.new.talk("monster","jump

ruby - Redmine邮箱配置: "undefined method ` email_delivery =' for ActionMailer::Base:Class"

我在第一次安装Redmine后为Redmine配置电子邮件通知。我创建了/etc/redmine/default/email.yml并添加了:#Outgoingemailsettingsproduction:email_delivery:delivery_method::smtpsmtp_settings:address:smtp.example.comport:25domain:example.comauthentication::loginuser_name:examplepassword:example访问时http://redmine/我遇到一个应用程序异常:“ActionMa

ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?

我正在尝试在prawn类中使用rails3.2助手,但rails抛出:undefinedmethod`number_with_precision'for#Prawn类classQuotePdfControllerdefshow@quote=current_user.company.quotes.where(:id=>params[:id]).firsthead:unauthorizedandreturnunless@quoterespond_with@quote,:layout=>!params[:_pjax]do|format|format.pdfdosend_dataQuotePd

ruby-on-rails - PinsController#index : declare the formats your controller responds to in the class level 中的运行时错误

在我的Rails应用程序上工作时,我在终端中使用以下命令创建了一个“Pins”脚手架:railsgeneratescaffoldPinsdescription:string--skip-stylesheets这会在我的应用程序中创建脚手架,然后我运行:rakedb:migrate一切顺利。我没有更改任何生成的页面,但是当我最终尝试访问localhost:3000上的新脚手架时,出现以下错误:RuntimeErrorinPinsController#indexInordertouserespond_with,firstyouneedtodeclaretheformatsyourcontr

ruby - 如何使用 Devise 来保护 delayed_job_web 接口(interface)?

我正在使用delayed_job_webgem来监控延迟的作业。https://github.com/ejschmitt/delayed_job_web可以使用我的routes.rb中的这一行访问它:match"/delayed_job"=>DelayedJobWeb,:anchor=>false我站点的每个其他区域都需要使用Devisegem登录。我如何使它也需要登录?在自述文件中,他们建议将以下内容添加到config.rb:ifRails.env.production?DelayedJobWeb.useRack::Auth::Basicdo|username,password|us

ruby-on-rails - rails : how to extend a gem's ActiveRecord child class?

我在扩展一个在gem中定义并且是ActiveRecord::Base的子类的类时遇到问题。我唯一想扩展这个类的是:有很多:promos然而,扩展倾向于排除原始类。我得到的错误:PGError:ERROR:relation"sites"doesnotexistLINE4:WHEREa.attrelid='"sites"'::regclass^:SELECTa.attname,format_type(a.atttypid,a.atttypmod),d.adsrc,a.attnotnullFROMpg_attributeaLEFTJOINpg_attrdefdONa.attrelid=d.a

ruby - "const_missing"定义中缺少常量和 "class << self"

在定义const_missing时,我对Ruby的行为感到非常困惑和class中的其他类方法定义而不是使用defself.foo句法。我正在尝试做这样的事情:classFooclass我主要使用class定义类方法的语法。但是,它没有按预期工作。const_missing永远不会被调用。以上结果导致NameError。像这样定义这两种方法按预期工作:defself.fooputsMISSINGenddefself.const_missing(name)puts"#{name}missing"end我认为classsyntax只是定义类方法的另一种方式,但完全等同于defself.foo

Ruby 2.4.1 Dir.children( dirname ) 为 Dir :Class"返回 "undefined method ` children'

我是Ruby的新手,正在尝试学习它。我使用的是最新的Ruby版本(2.4.1)和交互式RubyShell。我在Dir类中遇到过children方法。我试过这个例子fromthedocumentation:Dir.children("testdir")#=>["config.h","main.rb"]但它似乎不起作用,因为我收到以下消息:undefinedmethod`children'forDir:Class我错过了什么? 最佳答案 这似乎是某种文档困惑。Dir.children方法是在Feature#11302中引入的进入Ruby

ruby - 在 Ruby 中编写 C 接口(interface)比在 Perl 中更容易吗?

根据officialrubyAboutpage用C扩展Ruby比用Perl更容易。我不是(perl)XS专家,但我发现使用Inline::C快速简单地编写一些东西非常简单,那么为什么在Ruby中更容易呢?WritingCextensionsinRubyiseasierthaninPerlorPython,withaveryelegantAPIforcallingRubyfromC.ThisincludescallsforembeddingRubyinsoftware,foruseasascriptinglanguage.ASWIGinterfaceisalsoavailable.那些做

ruby - 为什么 Ruby 人说他们不需要接口(interface)?

Ruby是否与其他OOP语言(例如:PHP)不同,使接口(interface)变得无用?它有某种替代品吗?编辑:一些说明:在其他语言中(例如:PHP),您并不“需要”接口(interface)(它们在代码级别不是强制性的)。你用它们来订立契约(Contract),改进软件的架构。因此,'在ruby​​中你不需要接口(interface)/在其他语言中你需要接口(interface)因为XXX'的断言是错误的。不,混合不是接口(interface),它们是完全不同的东西(PHP5.4实现了混合)。你用过接口(interface)吗?是的,PHP是OOP。语言不断发展,欢迎来到现在。