Skip to content

Instantly share code, notes, and snippets.

@soutaro
Last active August 29, 2015 14:16
Show Gist options
  • Save soutaro/e96d883bf31ce599ef4c to your computer and use it in GitHub Desktop.
Save soutaro/e96d883bf31ce599ef4c to your computer and use it in GitHub Desktop.
remove_const
module A
module B
module C
def self.f()
puts "X = #{X}"
end
end
end
end
a = ::A
b = ::A::B
c = ::A::B::C
X = "::X"
c.f
A::X = "::A::X"
c.f
A::B::X = "::A::B::X"
c.f
a.class_eval do
remove_const :B
end
c.f # => "::A::B::X", why not "::A::X"?
b.class_eval do
remove_const :X
end
c.f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment