草庐IT

php常量和EOT

全部标签

ruby - Ruby 中更快的常量时间字符串比较

我正在尝试将用户提供的身份验证token与存储在我的服务器上的身份验证token进行比较。最明显的方法就是使用==,但这可能会造成定时攻击。为了缓解这种情况,我编写了这个安全比较函数:#stringcomparisonthatleaksnoinformationaboutthestrings.#looselybasedonhttps://github.com/rack/rack/blob/master/lib/rack/utils.rb#andhttp://security.stackexchange.com/questions/49849/timing-safe-string-com

ruby - 类中的常量 << self block

在下面的片段中,是否可以从模块外部引用FOO常量,如果可以,如何?moduleXclass 最佳答案 class或classObjectdefmetaclassclass 关于ruby-类中的常量 https://stackoverflow.com/questions/2281057/

ruby-on-rails - Rails & Redcarpet:在 ApplicationHelper 中使用时未初始化的常量 Redcarpet::Render

我正在关注SyntaxHighlightingRevised的RailsCasts剧集.我将我的ApplicationHelper更新为如下所示:require'redcarpet'moduleApplicationHelperclassHTMLwithPygments但是,我的网络应用返回RoutingErroruninitializedconstantRedcarpet::RenderTryrunningrakeroutesformoreinformationonavailableroutes.我使用的是Rails3.2.11,Redcarpet在Rails控制台中响应良好。我最初

ruby-on-rails - 使用自定义异常时未初始化的常量

我正在尝试为我的应用创建自定义异常(exception)。我的libs文件夹中有一个示例库,其文件夹结构如下:-lib/||--social/||--bandcamp.rb这个bandcamp.rb文件内容如下:moduleSocialclassExampleException问题是,我可以在我的应用程序中的任何地方使用Social::Bandcamp.new.some_method,它工作得很好,但我无法访问Social::ExampleException也不会在任何地方提出。它给了我NameError:uninitializedconstantSocial::ExampleExce

ruby - 为什么方法调用在原则上可以是常量时需要消除歧义?

方法调用通常可以省略接收者和参数的括号:deffoo;"foo"endfoo#=>"foo"在上面的例子中,foo在方法调用和对潜在局部变量的引用之间是不明确的。在没有后者的情况下,它被解释为方法调用。但是,当方法名原则上可以是常量名时(即,当它以大写字母开头,并且仅由字母组成时),似乎需要消歧。defFoo;"Foo"endFoo#=>NameError:uninitializedconstantFooFoo()#=>"Foo"self.Foo#=>"Foo"为什么会这样?为什么即使在没有同名常量的情况下,也需要明确区分方法调用和对常量的引用? 最佳答案

ruby-on-rails - 有没有办法在带有 rails 的 yaml 中引用常量?

有没有办法让我的en.yml文件包含一个常量?#en.ymlfoo:bar:IloveBAZsomuch!#initializers/constants.rbBAZ="stackoverflow.com"I18n.t("foo.bar")->"Ilovestackoverflow.comsomuch!"?如果没有,有没有办法自己引用yaml文件?foo:bar:Ilove*baz*somuch!baz:stackoverflow.comI18n.t("foo.bar")->"Ilovestackoverflow.comsomuch!" 最佳答案

ruby - 'case' 语句如何使用常量?

我正在使用Ruby1.9.2和RubyonRails3.2.2。我有以下方法:#Note:The'class_name'parameterisaconstant;thatis,itisamodelclassname.defmy_method(class_name)caseclass_namewhenArticlethenmake_a_thingwhenCommentthenmake_another_thingwhen...then...elseraise("Wrong#{class_name}!")endend我想明白为什么在上面的case语句中,当我执行方法调用时它总是运行else“

ruby-on-rails - 未初始化的常量设计 RSPEC

我正在使用带有RSpec和Capybara的Rails4应用程序。我的gemfile看起来像:source'https://rubygems.org'gem'rails','4.0.0'gem'pg'gem'devise'gem'sass-rails','~>4.0.0'gem'uglifier','>=1.3.0'gem'coffee-rails','~>4.0.0'gem'jquery-rails'gem'jquery-turbolinks'gem'turbolinks'gem"rspec-rails",:group=>[:test,:development]group:testd

ruby - 是否有可能缩小 ruby 常量查找

我有一个模块,其中包含名为String的类(以及其他类。)我需要按名称查找该类,如果没有这样的类,则优雅地回退。moduleMod1moduleStringendendMod1.const_get'String'#⇒Mod1::StringKernel.const_get'::Mod1::String'#⇒Mod1::String到目前为止,还不错。当我尝试查找不存在的类时,我预计会收到NameError,这很好。问题是如果在全局命名空间中存在一个具有给定名称的类,它将被返回:Mod1.const_get'Fixnum'#⇒Fixnum我明白其中的原因,但我的问题是:是否有现成的方法仅

ruby-on-rails - 在 ActiveSupport::Concern 中访问包含类的 protected 常量

在ActiveSupport::Concern上下文中访问包含类的protected常量的最简单方法是什么?示例类:modulePrintableextendActiveSupport::Concernprivatedefprint_constantputsMY_CONSTANTendendclassPrinterincludePrintabledefprintprint_constantendprivateMY_CONSTANT='Hello'.freezeend此解决方案产生错误:NameError:uninitializedconstantPrintable::MY_CONSTA