類別 DidYouMean::VerboseFormatter

DidYouMean::Formatter 是此寶石的基本預設格式化器。格式化器會回應 message_for 方法,並傳回人類可讀的字串。

公開類別方法

message_for(corrections) 按一下以切換來源

傳回包含 corrections 的人類可讀字串。此格式化器設計為較不冗長,以避免佔用太多螢幕空間,同時對使用者來說又夠有幫助。

@example

formatter = DidYouMean::Formatter.new

# displays suggestions in two lines with the leading empty line
puts formatter.message_for(["methods", "method"])

Did you mean?  methods
                method
# => nil

# displays an empty line
puts formatter.message_for([])

# => nil
# File lib/did_you_mean/formatter.rb, line 29
def self.message_for(corrections)
  corrections.empty? ? "" : "\nDid you mean?  #{corrections.join("\n               ")}"
end

公開實例方法

message_for(corrections) 按一下以切換來源
# File lib/did_you_mean/formatter.rb, line 33
def message_for(corrections)
  warn "The instance method #message_for has been deprecated. Please use the class method " \
       "DidYouMean::Formatter.message_for(...) instead."

  self.class.message_for(corrections)
end