Created
December 9, 2011 16:01
-
-
Save cassiomarques/1452110 to your computer and use it in GitHub Desktop.
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
class A | |
def self.create_sub_class(name) | |
c= Class.new(self) | |
const_set name, c | |
end | |
end | |
A.create_sub_class "B" | |
A::B # ok! | |
# mas eu queria criar só B, no escopo global | |
B # uninitialized constant B (NameError) |
tinogomes
commented
Dec 9, 2011
porém
class A; end
=> nil
1.9.2 (main)> A::C.new
(pry):14: warning: toplevel constant C referenced by A::C
=> #<C:0x0000010131d3d0>
Valeu @tinogomes, era disso que eu precisava. Óbvio né? A solução que eu queria era algo simples e eu imaginando altas doideras aqui. Obrigado!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment