Skip to content

Commit

Permalink
Make constantize look into ancestors
Browse files Browse the repository at this point in the history
[#410 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>

Conflicts:

	activesupport/lib/active_support/inflector.rb
  • Loading branch information
jeremy committed Dec 15, 2008
1 parent d0a3dbf commit eca79e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 1 addition & 3 deletions activesupport/lib/active_support/inflector.rb
Expand Up @@ -281,9 +281,7 @@ def constantize(camel_cased_word)
names.shift if names.empty? || names.first.empty?

constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
names.each { |name| constant = constant.const_get(name) }
constant
end

Expand Down
17 changes: 16 additions & 1 deletion activesupport/test/inflector_test.rb
Expand Up @@ -2,8 +2,21 @@
require 'inflector_test_cases'

module Ace
module Extension
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def mission_accomplished?
false
end
end
end

module Base
class Case
include Extension
end
end
end
Expand Down Expand Up @@ -121,7 +134,9 @@ def test_constantize
end

def test_constantize_does_lexical_lookup
assert_raises(NameError) { ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest") }
assert_equal InflectorTest, ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest")
assert_nothing_raised { Ace::Base::Case::ClassMethods }
assert_nothing_raised { assert_equal Ace::Base::Case::ClassMethods, ActiveSupport::Inflector.constantize("Ace::Base::Case::ClassMethods") }
end

def test_ordinal
Expand Down

0 comments on commit eca79e6

Please sign in to comment.