如何使用礼物?在 Ruby 项目中? [英] How to use present? in Ruby projects?
本文介绍了如何使用礼物?在 Ruby 项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个脚本,它使用 Rails 对 Ruby 核心 Object 类的扩展,现在我想将它独立出来.有没有什么库或扩展可以让我独立使用它们,而不是重写这些?
I wrote a script that uses Rails' extensions to the Ruby core Object class, and now I want to spin it off on its own. Rather than rewriting these, is there any library or extension that I can use to make them available independently?
推荐答案
您不必运行 Rails 即可使用
You don't have to run Rails to use
require 'active_support/all'
或者如果您只想要一个特定的扩展名,例如 blank?
用于字符串,那么只需
or if you just want a specific extension, like blank?
for string then just
require 'active_support/core_ext/string'
我抬头 存在?
实际上定义为
def present?
!blank?
end
在主动支持中定义为空白
blank defined in active support as
def blank?
respond_to?(:empty?) ? !!empty? : !self
end
这篇关于如何使用礼物?在 Ruby 项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文