I just started working with a new company and have been trawling through the codebase as you do. And I came across the behavior listed in the title that symbols don’t have a method size within the Rails console. I’ve been on this wild goose chase for the last week reading through the source code of various gems etc. trying to figure out if it was Ruby version thing, something in my companies code base, or what.
I eventually tracked it down to, I believe, the rails console, but in going through the rails source code I haven’t been able to find any reference to Symbol.size.
Wondering if anyone here could provide context for whether I’m way off and, if I’m not, why the decision was made.
I’m able to use Symbol#size in a brand new Rails 5.1 application. Can you recreate the problem in a new Rails app? I suspect the #size method is missing in your application due to monkey patching Symbol in the app itself or one of its dependencies.
Hmm. Yeah, you are correct. Just spun up a fresh rails app also and found Symbol still has its size method. I’ll just keep wandering down dependencies till I find it.
Sometimes you fix something, but the fix is temporary, which means it is
expected to be eventually gone, should be gone better sooner than later.
This may happen in many scenarios, but to put an example: a gem you depend
on has a bug, you monkey patch it instead of forking because the fix is
trivial. That should be undone when the bug is fixed in the gem and you
upgrade. It is a temporary hack.
I said "typical" because it is not unsual that people forget they did
something "temporary" and that stays in the code base for a long time.
Maybe even they are gone and maintainers do not know under which
circumstances the temporary fix can be deleted, etc.
In practice that needs some kind of discipline. For example, in the use
case above I wrap the fix in a version check that raises if the version is
not the expected one (that is, the application cannot even boot if you
upgrade the gem). And that forces you to revisit that spot instead of
relying on memory. A code comment for maintainers does wonders too.
It could have been a typo and she or he meant a “temporary” fix (a fix intended to last only a short time), or the original coder could have meant it was a fix to address an issue related to time, as “temporal” is an adjective meaning “related to time.”
Generally if I saw that and I knew the coder had a sophisticated grasp of the English language, I’d assume the latter. If I thought the (obscure) word “temporal” was out of the coder’s vocabulary, I’d assume it was a typo and he had meant “temporary.”
But clearly Colin Law has the best interpretation — there was a rift in the spacetime continuum that needed a line of Ruby code to patch it.