這是一個關於如何在Ruby中定義方法和類以及如何讀取API文檔的問題。簡而言之:如何定義的create_table
方法/進口/繼承,因此它在ActiveRecord::Migration
可用,在這樣的代碼:這些方法如何在Rails Migration類中使用create_table?
class CreateProducts < ActiveRecord::Migration
def up
create_table :products do |t|
t.string :name
...
從Java世界的到來,我預計API docs提供指向基類或混入其中,一切都被定義了。但是,如果我查看Migration
的頁面,我會看到一些有用的手寫文檔,但沒有鏈接到create_table
的最詳細的權威定義。我用谷歌找到它ActiveRecord::ConnectionAdapters::SchemaStatements
,但即使看着這兩個文件的源代碼:
Migration in git
create_table in git
我看不出create_table
被帶入範圍在Migration
。該類中動態創建
我認爲這些方法僅在類eval的類CommandRecorder中定義。 – Kaeros 2013-03-20 22:31:55
@Kaeros感謝您的糾正,從我的手機中查看它。我相應編輯。 – fmendez 2013-03-20 22:40:01
在遷移下沒有加載CommandRecorder?所以我可以說'Migration :: CommandRecorder.new.create_table',但不是'Migration.new.create_table'。 – 2013-03-21 15:37:15