Skip to content

Instantly share code, notes, and snippets.

@nagachika
Last active August 29, 2015 14:02
Show Gist options
  • Save nagachika/07c08782f3fbe0d7b14f to your computer and use it in GitHub Desktop.
Save nagachika/07c08782f3fbe0d7b14f to your computer and use it in GitHub Desktop.
ActiveSupport::Dependencies and const_get(const, false)
class A
def self.foo
puts "::A#foo"
end
end
require "active_support/dependencies"
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
class B
end
B.const_get(:A, false).foo rescue p $! # => ::A#foo
A.foo rescue p $! # => ::A#foo
B.const_get(:A, false).foo rescue p $! # => #<NameError: uninitialized constant B::A>
source "https://rubygems.org"
#gem "activesupport", "~> 3.2.18"
gem "activesupport", "~> 4.1.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment