4 module DidYouMean class ClassNameChecker include SpellCheckable def initialize(exception) @class_name, @receiver = exception.name, exception.receiver end def candidates { @class_name => class_names } end # generates a dictionary def class_names scopes.flat_map do |scope| scope.constants.map do |constant| scope == Object ? constant : "#{scope}::#{constant}" end end end def scopes @receiver.to_s.split("::").inject([Object]) do |_scopes, scope| _scopes << _scopes.last.const_get(scope) end.uniq end end end