Created
November 6, 2012 20:32
-
-
Save mbj/4027322 to your computer and use it in GitHub Desktop.
Anonymous ruby class names?
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
klass = Class.new # an anonymous class | |
klass.name # => "" does not have a name | |
Foo = klass # but when assigned to a constant: | |
p klass.name # => "Foo" it has a name! Magic! *happy* | |
Bar = klass # Again? | |
p klass.name # => "Foo" no magic :( | |
p Bar.name # => "Foo" still... | |
# Really like ruby outside of unavoidable edge cases! | |
# The assumption Class.new.name == nil can also be broken far far away from Class.new! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment