Exception: Empirical::NameError

Inherits:
NameError
  • Object
show all
Defined in:
lib/empirical/name_error.rb

Constant Summary collapse

INSTANCE_VARIABLE_METHOD =
Kernel.instance_method(:instance_variables)

Instance Method Summary collapse

Constructor Details

#initialize(object, name) ⇒ NameError

Returns a new instance of NameError.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/empirical/name_error.rb', line 8

def initialize(object, name)
	checker = DidYouMean::SpellChecker.new(
		dictionary: INSTANCE_VARIABLE_METHOD.bind_call(object)
	)

	suggestion = checker.correct(name).first

	message = [
		"Undefined instance variable `#{name}`.",
		("Did you mean `#{suggestion}`?" if suggestion),
	].join(" ")

	super(message)
end