When you mistype an instance variable you get an error like:
undefined method `some_method' for nil:NilClass
which can be very confusing for a newcomer.
I’m not saying we should reintroduce WhinyNils, but some DidYouMean like functionality would be really helpful.
I like the idea of hooking into DidYouMean. Maybe there’s an opportunity for a PR there that monkeypatches nil? Or some other deeply ridiculous, deeply Rubyish thing that Just Might Work?
Looks like DYM has experimental support for ivars. We might be able to add a tracepoint for uninitialized ivars, but I know people commonly leave ivars uninitialized and disable warnings so it might be a perf hit for that code.
I made a PR for tracepoints on uninitialized ivars here. I will be very honest and say I haven’t thought of the consequences. It may break patterns like:
The OP example wasn’t clear to me, I guess it’s from something like @mistyped_ivar.some_method.
I think using ruby -w or $VERBOSE = true or ruby -d is a good way to catch those.