3

I saw the below declaration in some program.

class Animal::Cat < Animal

What do these double colons mean?

Does it mean that the Cat class is in the Animal namespace?

Otherwise, the class name itself is Animal::Cat?

Iwao Nishida
  • 866
  • 6
  • 6

1 Answers1

4

It's another (I think neater) way of writing:

module Animal
  class Cat
  end
end

Alternatively, if you were in the class Dog and saw:

class Dog
  def new_cat
    ::Cat.new
  end
end

You would know you were talking about the Cat class, and not the Dog::Cat class

Mark
  • 6,112
  • 4
  • 21
  • 46