1

Given this piece of Code:

 class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.string :commenter
      t.text :body
      t.references :article, index: true

      t.timestamps
    end
  end
end

I understand that CreateComments inherits methods from Migration. But what is Migration to ActiveRecord? Compared to other languages, I could not find any member named Migration in the ActiveRecord class. So what does the :: mean? What do you call Migration in this case?

Chrisissorry
  • 1,434
  • 2
  • 22
  • 43

2 Answers2

3

here actually Migration is a class and ActiveRecord is module (namespace). So definition is:

module ActiveRecord
    class Migration
        ....
    end
end

base definition of the class Migration is in the file /activerecord/lib/active_record/migration.rb

so, in order to call class Migration, you should specify in which module it is, therefore you have ActiveRecord::Migration

Marko Krstic
  • 1,417
  • 1
  • 11
  • 13
0

ActiveRecord is a namespace, Migration is a class
more information in documentation
http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

wish it helps

itsnikolay
  • 17,415
  • 4
  • 65
  • 64