Created
May 25, 2012 14:46
-
-
Save djberg96/2788511 to your computer and use it in GitHub Desktop.
Rescoping a class within a module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
end | |
class Bar | |
def initialize | |
puts "Hello, this is Bar" | |
end | |
end | |
class Baz | |
def initialize | |
puts "Hello, this is Baz" | |
end | |
end | |
module Foo | |
Bar = ::Bar | |
class Baz < ::Baz; end | |
end | |
p Foo::Bar.new | |
p Foo::Baz.new | |
# Output | |
Hello, this is Bar | |
#<Bar:0x0000010092d370> | |
Hello, this is Baz | |
#<Foo::Baz:0x0000010092d2d0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment