Skip to content
  • Jean Boussier's avatar
    11e05def
    Fix constantize edge case involving prepend, autoloading and name conflicts · 11e05def
    Jean Boussier authored
    In the following situation:
    
    ```ruby
    class Bar
    end
    
    module Baz
    end
    
    class Foo
      prepend Baz
    end
    
    class Foo::Bar
    end
    ```
    
    Running `Inflector.constantize('Foo::Bar')` would blow up with a NameError.
    
    What is happening is that `constatize` was written before the introduction
    of prepend, and wrongly assume that `klass.ancestors.first == klass`.
    
    So it uses `klass.ancestors.inject` without arguments, as a result
    a prepended module is used in place of the actual class.
    11e05def
    Fix constantize edge case involving prepend, autoloading and name conflicts
    Jean Boussier authored
    In the following situation:
    
    ```ruby
    class Bar
    end
    
    module Baz
    end
    
    class Foo
      prepend Baz
    end
    
    class Foo::Bar
    end
    ```
    
    Running `Inflector.constantize('Foo::Bar')` would blow up with a NameError.
    
    What is happening is that `constatize` was written before the introduction
    of prepend, and wrongly assume that `klass.ancestors.first == klass`.
    
    So it uses `klass.ancestors.inject` without arguments, as a result
    a prepended module is used in place of the actual class.
Loading