::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.

Answers


::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.

May I suggest picking up the Pickaxe book or reading Why's (Poignant) Guide to Ruby.


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

Need Your Help

Event binding on underscore/lodash templates

javascript jquery lodash underscore.js-templating

I have an example lodash template inside a jquery plugin as shown below:

How to fetch data from secondary calendars in google calendars?

java android google-calendar-api

I am writing a code that displays all events of all calendars synced with a particular Gmail account.But I am able to get data from primary calendar only . Can someone help in how to do it for seco...