4 ms·
> How do you know which 'Date' your are using. How do you know it's the one from 'date'? Ruby allows you to check where a method is defined, e.g.: puts D
by shaicoleman 4y ago
> How do you know which 'Date' your are using. How do you know it's the one from
'date'?
Ruby allows you to check where a method is defined, e.g.:
puts Date.singleton_method(:today).source_location
Although in this case it returns nil because it's implemented in C. But it would return the location if you overrode it.
There are various tools to see what the code is doing: invoking a debugger and stepping into the code, tracing the code execution via TracePoint, etc.
The Zeitwerk autoloader which comes with Rails enforces that the class name matches the filename.
Naming conventions, specs, a quick grep and avoiding generic names make it almost a non-issue in my experience - only happens every few years or so, and usually quite easy to fix.
Ruby gives you a lot of power, but it doesn't stop you from shooting yourself in the foot.
https://m.signalvnoise.com/provide-sharp-knives/ https://m.signalvnoise.com/provide-sharp-knives/