类 DidYouMean::VerboseFormatter

DidYouMean::Formatter 是该 gem 的基本默认格式化程序。该格式化程序响应 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