Ticket #10470: const_missing_ruby_1.9_compat.diff
| File const_missing_ruby_1.9_compat.diff, 2.3 kB (added by chuyeow, 10 months ago) |
|---|
-
lib/active_support/dependencies.rb
old new 216 216 end 217 217 218 218 # Load the constant named +const_name+ which is missing from +from_mod+. If 219 # it is not possible to l aod the constant into from_mod, try its parent module219 # it is not possible to load the constant into from_mod, try its parent module 220 220 # using const_missing. 221 221 def load_missing_constant(from_mod, const_name) 222 222 log_call from_mod, const_name … … 236 236 unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id 237 237 raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" 238 238 end 239 239 240 240 raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name) 241 241 242 242 qualified_name = qualified_name_for from_mod, const_name … … 460 460 end 461 461 462 462 class Class 463 def const_missing(class_id) 463 def const_missing(const_name) 464 # Bypass entire lookup process if we can get the constant from Object. 465 # This is useful for Ruby 1.9 where Module#const_defined? looks up the 466 # ancestors in the chain for the constant. 467 return ::Object.const_get(const_name) if ::Object.const_defined?(const_name) 468 464 469 if [Object, Kernel].include?(self) || parent == self 465 470 super 466 471 else 467 472 begin 468 473 begin 469 Dependencies.load_missing_constant self, c lass_id474 Dependencies.load_missing_constant self, const_name 470 475 rescue NameError 471 parent.send :const_missing, c lass_id476 parent.send :const_missing, const_name 472 477 end 473 478 rescue NameError => e 474 479 # Make sure that the name we are missing is the one that caused the error 475 parent_qualified_name = Dependencies.qualified_name_for parent, c lass_id480 parent_qualified_name = Dependencies.qualified_name_for parent, const_name 476 481 raise unless e.missing_name? parent_qualified_name 477 qualified_name = Dependencies.qualified_name_for self, c lass_id482 qualified_name = Dependencies.qualified_name_for self, const_name 478 483 raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) 479 484 end 480 485 end