Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

"".constantize returns Object

#6432

Not 100% sure if this should be considered a bug, but I found it a bit unexpected and it masked a bug in a project I was working:

ruby-1.9.2-p136 :001 > "".constantize
 => Object 
ruby-1.9.2-p136 :003 > "".constantize == ::Object
 => true

I expected an error, as if I had done:

ruby-1.9.2-p136 :008 > Object.const_get("")
NameError: wrong constant name

Reported by alindeman · February 14th, 2011 @ 10:06 PM

State: open
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. alindeman
    alindeman

    First try at a patch + test attached.

    February 15th, 2011 @ 05:00 AM

  2. Andrew White
    Andrew White
    • State changed from new to open
    • Importance changed from to Low

    I'm still not sure this is a bug - the default receiver in global namespace is Object and the existing code does take into account the possibility of an empty names array. I'll ask Jeremy Kemper since he wrote the original code.

    February 15th, 2011 @ 06:29 AM