如何确保Ruby使用不易受Heartbleed攻击的OpenSSL?

关于Heartbleed错误, ruby-lang.org上的这篇文章描述了如何检查漏洞和升级。 它包括这个建议: 要validation链接到Ruby的OpenSSL库的哪个版本,请使用以下命令: ruby -v -ropenssl -rfiddle -e ‘puts Fiddle::Function.new(Fiddle.dlopen(nil)[“SSLeay_version”], [Fiddle::TYPE_INT], Fiddle::TYPE_VOIDP).call(0)’ 要validation当前使用Ruby安装的OpenSSL的版本,请使用以下命令: ruby -ropenssl -e ‘puts OpenSSL::OPENSSL_VERSION’ 这两个检查有什么区别,如果从任一命令返回错误版本,建议采取什么操作?

如何修复Rubygems最近的弃用警告?

我最近运行更新: gem update –system gem update 现在,每次加载gem时,我都会收到很多弃用警告。 例如, rails console : NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01. Gem::Specification#default_executable= called from /Users/user/.rvm/gems/ruby-1.9.2-p180@global/specifications/rake-0.8.7.gemspec:10. NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01. Gem::Specification#default_executable= called from /Users/user/.rvm/gems/ruby-1.9.2-p180@global/specifications/rake-0.8.7.gemspec:10. NOTE: Gem::Specification#default_executable= is deprecated with no […]

为什么我可以引用从未运行的if / unless / case语句之外的变量?

为什么以下代码不会抛出错误? if false x = 0 end x #=> nil 以下确实会引发错误: y # NameError: undefined local variable or method `x’ for main:Object unless & case语句也会发生同样的事情。

什么时候Ruby中的’eval`是合理的?

“ ‘eval’应该是令人讨厌的吗? ”这启发了这个: 大多数人都同意eval是坏的,并且在大多数情况下更优雅/更安全。 所以我想问一下:如果经常误用eval ,它真的需要作为语言function吗? 这是邪恶而不是好吗? 就个人而言,我发现它唯一有用的地方是插入配置文件中提供的字符串。 编辑:这个问题的目的是在eval是唯一或最佳解决方案时尽可能多地获得真实案例。 所以,请不要进入“应该用语言限制程序员的创造力”的方向。 Edit2:当我说eval时,我当然是指eval ing字符串,而不是将ruby块传递给instance_eval或class_eval 。

Rails和类变量

class MainController < ApplicationController @my_var = 123 def index var1 = @my_var end def index2 var2 = @my_var end end 为什么var1没有var2等于123 ?

Ruby on Rails:如何在后台运行东西?

创建新资源并且在资源准备好之前需要进行一些冗长的处理时 ,如何将该处理发送到后台 ,它不会阻止当前请求或其他流量到我的网络应用程序? 在我的模型中: class User < ActiveRecord::Base after_save :background_check protected def background_check # check through a list of 10000000000001 mil different # databases that takes approx one hour 🙂 if( check_for_record_in_www( self.username ) ) # code that is run after the 1 hour process is finished. user.update_attribute( :has_record ) end end end

Ruby gsub不会逃避单引号

我不明白这里发生了什么。 我应该如何提供gsub来获取字符串“Yaho \’o”? >> “Yaho’o”.gsub(“Y”, “\\Y”) => “\\Yaho’o” >> “Yaho’o”.gsub(“‘”, “\\'”) => “Yahooo”

如何在Ruby中设置SSLContext选项

我需要在Ruby 1.8+中创建一个SSLSocket来与加密服务进行通信。 我想在SSLContext对象上设置SSL选项(它最终调用底层OpenSSL库中的SSL_CTX_set_options )。 我没有看到任何明显的方法来做到这一点。 这是使用OpenSSL::SSL::SSLContext接口。 作为参考,这类似于在Python的pyOpenSSL库中调用set_options() 。

关于将实例变量传递给redirect_to方法的困惑。 正如Rails指南中所见

我正在研究rails指南上的ruby,即http://guides.rubyonrails.org/layouts_and_rendering.html上的“布局和渲染”主题 我很困惑将实例变量传递给redirect_to方法。 这怎么可能? 我认为redirect_to与重定向到另一个网页或url有关。 在指南中给出的示例中,它说明如下: 2.2.2渲染动作视图 如果要在同一模板中呈现与不同操作对应的视图,可以使用带有视图名称的render: def update @book = Book.find(params[:id]) if @book.update_attributes(params[:book]) redirect_to(@book) else render “edit” end end 渲染“编辑”完全有意义,它将再次渲染新forms。 但是redirect_to(@book)在世界上发生了什么? 究竟是什么呈现以及如何将书籍对象重定向到? 顺便说一句,书籍模型有专栏,名称,作者,页面等…

在Ruby中将unicode代码点转换为字符串字符

我从unicode数据库获得这些值,但我不确定如何将它们转换为人类可读的forms。 这甚至叫什么? 他们来了: U+2B71F U+2A52D U+2A68F U+2A690 U+2B72F U+2B4F7 U+2B72B 如何将这些转换为可读符号?