Skip to content

Instantly share code, notes, and snippets.

@mbj
Created November 6, 2012 20:32
Show Gist options
  • Save mbj/4027322 to your computer and use it in GitHub Desktop.
Save mbj/4027322 to your computer and use it in GitHub Desktop.
Anonymous ruby class names?
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