class DidYouMean::VerboseFormatter

DidYouMean::Formatter 类是 gem 的基本默认格式化程序。该格式化程序响应 message_for 方法,并返回人类可读的字符串。

公共类方法

message_for(corrections) 点击切换源代码

返回包含 corrections 的人类可读字符串。此格式化程序的设计目标是减少冗长,避免占用过多屏幕空间,同时对用户足够有帮助。

@示例

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 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 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