#478 ✓resolved
Alexander Flatter

Extlib's Module::find_const does not work properly when searching siblings

Reported by Alexander Flatter | July 22nd, 2008 @ 10:05 PM

>> require 'extlib'
=> true
>> module Foo
>>   module Bar
>>   end
>> end
=> nil
>> Foo.find_const('Bar')
=> Foo::Bar
>> Foo.find_const('Baz')
=> Foo # Should raise NameError
>> Object.find_const('Bar')
NameError: NameError
	from /Library/Ruby/Gems/1.8/gems/extlib-0.9.3/lib/extlib/module.rb:39:in `__nested_constants__'
	from /Library/Ruby/Gems/1.8/gems/extlib-0.9.3/lib/extlib/module.rb:9:in `find_const'
	from (irb):17
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1239

Comments and changes to this ticket

  • Alexander Flatter
  • Alexander Flatter

    Alexander Flatter July 22nd, 2008 @ 10:04 PM

    BTW:

    >> Object.find_const('Foo::Baz')
    => Foo
    
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 23rd, 2008 @ 02:15 AM

    • State changed from “new” to “resolved”
    • Tag changed from extlib, module to bug, extlib, module, spec
    • Assigned user changed from “Sam Smoot” to “Dan Kubb (dkubb)”

    This should be resolved by the following commit:

    http://github.com/sam/extlib/com...

  • Alexander Flatter

    Alexander Flatter July 23rd, 2008 @ 08:26 AM

    Looks like that patch messed up auto migrations... Perhaps that bug provoked more bugs in dm-core.

    I did reimplement that method too but you committed earlier (+ your version performed better) :-)

  • Alexander Flatter

    Alexander Flatter July 23rd, 2008 @ 08:37 AM

    My wrong... Forgot to require a model. Looks okay.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 23rd, 2008 @ 03:23 PM

    I was actually thinking that prior to this change the system wouldn't throw a NameError exception when it should be doing so, since in your example Foo.find_const('Baz') returned Foo, and not NameError like it should be. I really like systems that "fail fast" when something is wrong, rather than try to hobble along like nothing happened, so I view this as a good thing.

  • Sam Smoot

    Sam Smoot July 23rd, 2008 @ 03:29 PM

    Dan,

    Right. Should raise a NameError. The idea is that #find_const should be a 100% drop-in replacement for #get_const, that just happens to be a bit more flexible in how it finds nested or sibling constants.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Attachments

Pages