Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created May 25, 2012 14:46
Show Gist options
  • Save djberg96/2788511 to your computer and use it in GitHub Desktop.
Save djberg96/2788511 to your computer and use it in GitHub Desktop.
Rescoping a class within a module
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