Symbol missing it's `.size` method in the Rails console

25 views
Skip to first unread message

Colin Hart

unread,
Oct 13, 2017, 9:21:37 AM10/13/17
to Ruby on Rails: Core
Hi all! 

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. 

thanks in advance. 

C

Geoff Harcourt

unread,
Oct 13, 2017, 9:58:21 AM10/13/17
to rubyonra...@googlegroups.com
Hi Colin,

What Ruby and Rails versions are you using? 

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.

-Geoff

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Xavier Noria

unread,
Oct 13, 2017, 10:15:27 AM10/13/17
to rubyonrails-core
Symbol#size comes originally from Ruby.

Can you see if

    bin/rails runner 'p :foo.size'

prints 3?

If it does, what happens in the console?

Colin Hart

unread,
Oct 13, 2017, 10:20:04 AM10/13/17
to Ruby on Rails: Core
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. 

Thanks for taking the time. 

C


On Friday, October 13, 2017 at 9:58:21 AM UTC-4, Geoff Harcourt wrote:
Hi Colin,

What Ruby and Rails versions are you using? 

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.

-Geoff
On Fri, Oct 13, 2017 at 8:54 AM, Colin Hart <epic...@gmail.com> wrote:
Hi all! 

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. 

thanks in advance. 

C

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Colin Hart

unread,
Oct 13, 2017, 10:23:14 AM10/13/17
to Ruby on Rails: Core

Xavier Noria

unread,
Oct 13, 2017, 11:12:32 AM10/13/17
to rubyonrails-core
The typical temporal fix.

Colin Law

unread,
Oct 13, 2017, 11:19:46 AM10/13/17
to rubyonra...@googlegroups.com
Patching a discontinuity in the space-time continuum I expect

Colin

On 13 October 2017 at 16:11, Xavier Noria <f...@hashref.com> wrote:
> The typical temporal fix.

Colin Hart

unread,
Oct 13, 2017, 11:25:03 AM10/13/17
to Ruby on Rails: Core
What exactly is a temporal fix?

Xavier Noria

unread,
Oct 13, 2017, 11:37:48 AM10/13/17
to rubyonrails-core
On Fri, Oct 13, 2017 at 5:25 PM, Colin Hart <epic...@gmail.com> wrote:

What exactly is a temporal fix?

I was joking.

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.


 

Colin Hart

unread,
Oct 13, 2017, 11:49:32 AM10/13/17
to Ruby on Rails: Core
Gotcha, makes sense. Thanks for the detailed response! 

Jason Fleetwood-Boldt

unread,
Oct 16, 2017, 12:21:58 PM10/16/17
to rubyonra...@googlegroups.com
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.

-Jason



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

If you'd like to reply by encrypted email you can find my public key on jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org

Reply all
Reply to author
Forward
0 new messages