草庐IT

make_new_type

全部标签

ruby - 无法在 MacOS 10.14.2 Mojave : Error running '__rvm_make -j4' 上使用 RVM 安装任何 Ruby

将MacOS升级到10.14.2Mojave后,我无法再使用RVM安装任何Ruby版本。它总是给出这样的错误:$rvminstall2.5.3ruby-2.5.3-#removingsrc/ruby-2.5.3..Searchingforbinaryrubies,thismighttakesometime.Nobinaryrubiesavailablefor:osx/10.14/x86_64/ruby-2.5.3.Continuingwithcompilation.Pleaseread'rvmhelpmount'togetmoreinformationonbinaryrubies.Ch

ruby - 为什么 Date.new 不调用初始化?

我想创建Date的子类。一个正常的、健康的、年轻的ruby​​ist,没有被Date的实现的特殊性所伤害,会以下面的方式来解决这个问题:require'date'classMyDate然后继续以最预期的方式使用它......require'my_date'mdt=MyDate.new(2012,1,28)putsmdt.to_s...只是因为Date::new方法实际上是Date::civil的别名,它永远不会调用初始化。在这种情况下,最后一段代码打印“2012-01-28”而不是预期的“2012-12-25”。亲爱的Ruby社区,这是什么鬼?new别名是否有一些很好的理由,以便它忽略

ruby-on-rails - 无方法错误 : undefined method `get' when running rspec and making get/visit calls

我完全被困在这里,希望有人能指出我正确的方向。我正在尝试使用rspec来测试我的网络路由。我按照这里的例子:https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec我的规范文件被命名为:spec/requests文件夹中的api_tests_spec.rb。文件如下:require'spec_helper'describe"APITests"dodescribe"GET/regions"doit"shouldreturnavalidresponse"do#Runthegeneratoragai

Ruby 语法问题 : Rational(a, b) 和 Rational.new!(a, b)

今天我在Rational中遇到了奇怪的ruby​​语法类:Rational(a,b)(请注意,与普通的Ruby语法相比,缺少.new()部分)。与普通的new语法相比,这究竟意味着什么?更重要的是,我如何在自己的代码中实现这样的东西,为什么要实现这样的东西?专门针对Rational类,为什么使用这种语法而不是正常的实例化呢?为什么new方法在rational类中是私有(private)的?(以及我如何/为什么要在我自己的ruby​​代码中这样做?)预先感谢您的回答,特别是因为我问了这么多问题。 最佳答案 您所要做的就是声明一个与您的

ruby - 类与 Class.new,模块与 Module.new

class之间有什么区别?和Class.new&module和Module.new?我知道:Class.new/Module.new创建一个匿名class/module.当我们第一次将它分配给常量时,它变成了那个class的名称。/module.class/module自动执行此操作。当我们想要继承时,我们可以传递一个参数:Class.new(ancestor).当我们不指定祖先时,它被设置为Object.class使用此语法:classAClass.new返回object.classA返回nil.同样适用于module秒。我错过了什么吗? 最佳答案

ruby - 自定义 to_yaml 和 domain_type

我需要定义用于序列化/反序列化对象的自定义方法。我想做类似下面的事情。classPersondefto_yaml_type"!example.com,2010-11-30/Person"enddefto_yaml"stringrepresentingperson"enddeffrom_yaml(yaml)Person.load_from(yaml)endend声明序列化/反序列化的正确方法是什么? 最佳答案 好的,这就是我想出的classPersondefto_yaml_type"!example.com,2010-11-30/pe

ruby-on-rails - ruby + Mongoid : how to make a required field?

我使用Mongoid的githead版本(因为Rails4),我想制作一个字段必填文档:classMyClassincludeMongoid::Documentfield:name,type:String,required:true我有这个错误:Problem:Invalidoption:requiredprovidedforfield:name.Summary:Mongoidrequiresthatyouonlyprovidevalidoptionsoneachfielddefinitioninordertopreventun...我做错了什么? 最佳答案

Ruby:没有类的 'new'

我对Ruby的理解是“new”关键字总是与类名结合使用以创建类的新实例。在下面的代码中,可在https://gist.github.com/e9c0da1a6e92dd12cbc7找到,这是作为Ruby新手编程挑战赛的解决方案提交的,作者在没有实例化类的情况下使用了“new”关键字三次。在一种情况下,new(0,0)被分配给常量CLOSED。在另一种情况下,new(open,close)是函数的返回值。为什么要这样做?以这种方式使用时,"new"在做什么?它在创造什么?classOpenHoursattr_reader:open,:closedefinitialize(open,clo

ruby - Rails 'raise StandardError.new' 和 'raise StandardError' 之间的区别

为了处理Rails异常,我看到人们使用“raiseSomeException.new”或“raiseSomeException”,有什么区别?说如果我有课classUnableToCreateShipments我可以两者都做吗?raiseUnableToCreateShipmentsraiseUnableToCreateShipments.new或者用消息raiseUnableToCreateShipments,'myerrormessage'raiseUnableToCreateShipments.new('myerrormessage') 最佳答案

ruby - 杰基尔 : New posts not being generated

我正在建立一个jekyll博客。我将.md文件放在_posts文件夹中。在项目根目录下运行jekyll--server命令。但是jekyll只是重新生成旧帖子,新闻帖子不会添加到_site。可能是什么问题? 最佳答案 我终于找到了jekyll失败的原因。我在我的一篇帖子中使用的标题中有一个冒号(:)。我只需要用:替换它并且帖子解析得很好。 关于ruby-杰基尔:Newpostsnotbeinggenerated,我们在StackOverflow上找到一个类似的问题: