跳至內容 跳至搜尋
方法
B
E

執行個體公共方法

空白?()

如果 路徑名稱 是空的,就會是空白

Pathname.new("").blank?      # => true
Pathname.new(" ").blank?     # => false
Pathname.new("test").blank?  # => false

@return [真,假]

# File activesupport/lib/active_support/core_ext/pathname/blank.rb, line 13
def blank?
  to_s.empty?
end

存在()

如果指定的檔案存在回傳路徑名稱,否則回傳nil路徑名稱.存在等同於

pathname.exist? ? pathname : nil

例如類似這樣

content = pathname.read if pathname.exist?

會變成

content = pathname.existence&.read

@return [路徑名稱]

# File activesupport/lib/active_support/core_ext/pathname/existence.rb, line 20
def existence
  self if exist?
end