表時,我會看到在this ruby on rails tutorial下面的代碼:做什麼| t |創建與軌道
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
我無法弄清楚什麼是什麼「嗎| T |」是爲了。它有什麼好處?
這是一個塊,它是Ruby語言的一個特性。他們基本上是lambda。 –
他們不是lambda。 lambda是lambda。這與'Proc'不同,後者是一個塊的實例:'def x(&b); b.class; end; x {}#=> Proc' – Kaleidoscope