class DidYouMean::Formatter
DidYouMean::Formatter 是该 gem 的基本、默认格式化程序。该格式化程序响应 message_for 方法,并返回一个人类可读的字符串。
Public Class Methods
Source
# File lib/did_you_mean/formatter.rb, line 29 def self.message_for(corrections) corrections.empty? ? "" : "\nDid you mean? #{corrections.join("\n ")}" end
返回一个包含 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
Public Instance Methods
Source
# 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