2 ms·
This is one of my pet peeves with most languages' error messages - e.g in Ruby: 2.2.0 :001 > a = nil; b = " "; c = "a"; 2.2.0 :002 > a + b + c NoMethodError
by jordanthoms 12y ago
This is one of my pet peeves with most languages' error messages - e.g in Ruby:
2.2.0 :001 > a = nil; b = " "; c = "a";
2.2.0 :002 > a + b + c
NoMethodError: undefined method `+' for nil:NilClass
from (irb):2
It would be trivial to tell me what the name of the nil variable was - in this case it's obvious, but it's often not.
- adrusi 12y agoExcept in Ruby, that error is raised by `NilClass#method_missing`. `method_missing` gets to know the name of the method being called, and the arguments passed to it, but it deals with the value, not the variable. It wouldn't be "trivial" to report the name of the variable, it would probably involve intercepting all NoMethodErrors raised by NilClass and then dropping into the debugger to know where exactly execution stopped. I'm not sure this is even possible with the current architecture of the Ruby interpreter.
- nilved 12y agohttp://ruby-doc.org//core-1.8.7/Kernel.html#method-i-caller http://ruby-doc.org//core-1.8.7/Kernel.html#method-i-caller https://github.com/banister/method_source https://github.com/banister/method_source