jjzjj

is_integer

全部标签

ruby - Integer(value) 和 value.to_i 之间的区别

给定一个像这样的字符串对象:twohundred="200"做和做有什么区别:Integer(twohundred)#=>200和:twohundred.to_i#=>200有区别吗?是否建议使用其中一种? 最佳答案 如果num不是有效整数(您可以指定基数),Integer(num)将抛出ArgumentError异常。num.to_i将尽可能多地转换。例如:"2hi".to_i#=>2Integer("2hi")#=>throwsArgumentError"hi".to_i#=>0Integer("hi")#=>throwsArg

ruby-on-rails - 如何解决弃用警告 "Method to_hash is deprecated and will be removed in Rails 5.1"

我正在尝试更新到Rails5,我收到以下弃用警告:DEPRECATIONWARNING:Methodto_hashisdeprecatedandwillberemovedinRails5.1,asActionController::Parametersnolongerinheritsfromhash.Usingthisdeprecatedbehaviorexposespotentialsecurityproblems.Ifyoucontinuetousethismethodyoumaybecreatingasecurityvulnerabilityinyourappthatcanbee

ruby-on-rails - 类型错误 : no implicit conversion of Symbol into Integer

我在尝试更改散列的值时遇到了一个奇怪的问题。我有以下设置:myHash={company_name:"MyCompany",street:"Mainstreet",postcode:"1234",city:"MyCity",free_seats:"3"}defcleanupstringstring.titleizeenddefformatoutput=Hash.newmyHash.eachdo|item|item[:company_name]=cleanup(item[:company_name])item[:street]=cleanup(item[:street])output当我

ruby-on-rails - 安装 nokogiri : Failed to build gem native extension & libiconv is missing (OSX) 时出错

我尝试克隆thisrepo并运行bundleinstall。捆绑过程失败并抛出此错误:...Installingnokogiri1.6.2.1withnativeextensionsBuildingnokogiriusingpackagedlibraries.Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./Users/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/ruby-r./siteconf20151130-43880-pntnc6.rbextconf.rbBuildi

ruby - Integer 和 Fixnum 有什么区别?

我知道Fixnum类继承自Integer类。但它们之间的实际区别是什么?是否存在我们有时使用Fixnum而有时使用Integer的用例? 最佳答案 更新:从Ruby2.4开始,Fixnum和Bignum类都消失了,只有Integer.完全相同的优化仍然存在,但它们被视为“适当的”编译器优化,即在幕后,对程序员不可见。这有点令人困惑。Integer是您应该考虑的真实类。Fixnum基本上是一种性能优化,从一开始就不应该让程序员看到它。(将其与YARV中的flonum进行比较,后者完全作为VM内部的优化实现,并且从不向程序员公开。)基本

Ruby 类继承 : What is `<<` (double less than)?

class这是什么为了?我搜索了,但结果只告诉我有关字符串连接的信息... 最佳答案 虽然class是真的是单例类的语法,正如其他人所说,它最常用于在类定义中定义类方法。但是这两种用法是一致的。方法如下。Ruby允许您通过以下方式向任何特定实例添加方法:class这添加了一个方法foo对某个实例,不是对它的类,而是对那个特定实例。(实际上,foo被添加到实例的“单例类”,但这或多或少是一个实现怪癖。)上面的代码执行后,您可以将方法foo发送到某个实例:someinstance.foo=>"Hello."但是您不能将foo发送到同一类

ruby-on-rails - 如何修复 "Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0"

我创建了一个Ruby项目,但是在运行bundleupdate和bundleinstall时返回错误:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0它的图像是:http://i.imgur.com/dZMhI11.png?1我的gemfile是:ruby'2.0.0'#ruby-gemset=railstutorial_rails_4_0gem'rails','4.0.0'group:developmentdogem'sqlite3','1.3.8'endgem'sass-rails','4.0.0'gem'uglifier','2

ruby Gemspec 依赖项 : Is possible have a git branch dependency?

在mygem.gemspec中是否可能有一个git分支依赖项?我在想类似下面的事情:gem.add_runtime_dependency'oauth2',:git=>'git@github.com:lgs/oauth2.git'...但它不起作用。 最佳答案 这是不可能的,而且可能永远不会,因为对于RubyGems来说,允许gem开发人员要求用户安装特定的版本控制系统来访问gem是相当严厉的。Gem应该是独立的,具有最少的依赖项,以便人们可以在尽可能广泛的应用程序中使用它们。如果您想为自己的内部项目执行此操作,我的建议是使用Bund

ruby-on-rails - 正确执行 redirect_to :back in Ruby on Rails when referrer is not available

我在使用redirect_to:back时遇到问题。是的,它是推荐人。我经常遇到异常(ActionController::RedirectBackError)"NoHTTP_REFERERwassetintherequesttothisaction,soredirect_to:backcouldnotbecalledsuccessfully.Ifthisisatest,makesuretospecifyrequest.env[\"HTTP_REFERER\"]."我意识到这是由于推荐人不可用造成的。有没有一种方法,例如,可以在访问最后一个页面的每次访问时设置一个session变量,并且

ruby - 执行 rvm 时获取 "Warning! PATH is not properly set up"使用 2.0.0 --default

上面的第一次不起作用,第二次起作用。尝试为任何新的shell窗口将ruby​​版本设置为2.0.0。做$rvmuse2.0.0--default给予Warning!PATHisnotproperlysetup,'/home/durrantm/.rvm/gems/ruby-1.9.3-p125/bin'isnotatfirstplace,usuallythisiscausedbyshellinitializationfiles-checkthemfor'PATH=...'entries,itmightalsohelptore-addRVMtoyourdotfiles:'rvmgetsta