-
-
Save edisonywh/e9d1f7e00d441a7c451d3c4d72a9bc3f 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
ObjectSpace.count_objects[:T_CLASS] #=> 920 | |
Foo = Class.new | |
ObjectSpace.count_objects[:T_CLASS] #=> 922 | |
``` | |
Now, before we understand what `extend` is doing, we need to first understand `Singleton Class`, so bear with me, get through the next section and we’ll then be able to understand the `extend` magic! | |
## The one about Singleton Class | |
`Singleton Class`, like its alternative name, `Anonymous Class` suggests, is anonymous, thus does not show up in the ancestor chain(!!!) That doesn’t mean we can’t access the singleton class though, in fact, there’s a handy method called `.singleton_class` that we can use. | |
```ruby | |
class Foo | |
end | |
Foo.singleton_class #=> #<Class:Foo> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment