::Base part meaning in ActiveRecord::Base
What does ::Base part mean in Person < ActiveRecord::Base class declaration? I'm new to ruby and from what I've gathered so far, Person < ActiveRecord should be used. Thank you.
::Base is a class in module ActiveRecord. One of the things modules do is provide namespacing in Ruby. In Ruby you don't inherit from a module but you can mix it in using the include statement.
in Ruby, :: accesses static class or module constants. ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.
Edit: as Mike points out, in this case ActiveRecord is a module...
:: is a unary operator that lets you access a constant, module, or class defined inside another class or module. It is used to provide namespaces so that method and class names don't conflict with other classes by different authors.
When you see ActiveRecord::Base in Rails it means that in Rails ActiveRecord::Base is something like this
module ActiveRecord class Base end end
This means that a class called Base is inside a module ActiveRecord which is then referenced as ActiveRecord::Base
For better understanding of :: operator, just go through this example from tutorialspoint.com :
MR_COUNT = 0 # constant defined on main Object class module Foo MR_COUNT = 0 ::MR_COUNT = 1 # set global count to 1 MR_COUNT = 2 # set local count to 2 end puts MR_COUNT # this is the global constant puts Foo::MR_COUNT # this is the local "Foo" constant