方法
实例公共方法
blank?() 链接
nil 为 blank
nil.blank? # => true
@return [true]
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/blank.rb, line 56 def blank? true end
to_param() 链接
返回 self。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/to_query.rb, line 26 def to_param self end
to_query(key) 链接
返回经过 CGI 转义的 key。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/to_query.rb, line 21 def to_query(key) CGI.escape(key.to_param) end
try(*, &) 链接
调用 try 方法在 nil 对象上始终返回 nil。当在可能返回 nil 的关联中进行导航时,它会特别有用。
nil.try(:name) # => nil
未使用 try
@person && @person.children.any? && @person.children.first.name
使用 try
@person.try(:children).try(:first).try(:name)
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/try.rb, line 148 def try(*, &) nil end
try!(*, &) 链接
调用 try! 方法在 nil 对象上始终返回 nil。
nil.try!(:name) # => nil
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/core_ext/object/try.rb, line 155 def try!(*, &) nil end