Searching on ‘ruby AboutClasses’ gets no hits in SO nor in Google.
class Dog
end
fido = Dog.new
puts Dog.inspect
puts fido.inspect
The result is
AboutClasses::Dog
#<AboutClasses::Dog:0x6255f0>
Can you please explain:
- What the term
AboutClassesis? - The notation in the second result
#<xxxxx>. I understand it’s an instance, but why put the#<>around it?
Searching GitHub yields a bunch of Ruby source files containing
require 'about_classes', all of them in forks of ruby_koans.In fact, file about_classes.rb file contains a class Dog, named fido, within a class named
AboutClasses. I’m guessing you have loaded this class or are executing it.To answer your specific questions about
#<AboutClasses::Dog:0x6255f0>:The term “AboutClasses” is just a class or module name. You can nest them, so that the outer class or module acts like a namespace. That way, your Dog class doesn’t clash with the Dog class in some other gem you’ve loaded. When you nest them, the names are separated by
::.The notation
#<ClassName:MemoryAddress>is just a notation. The hash mark and angle bracket are just there to set it apart from, well, everything else.