title Metaprogramming Ruby 2 - ch1 - The M world
datetime 2016-04-10 13:20:04
tags mp,book_mr2,note,ruby
category coding
link mr2-ch1-the-m-world
file 2016-04-10-132004-mr2-ch1-the-m-world
template post
end
這是 Metaprogramming Ruby 2 的閱讀筆記,只會記錄我覺得重要的地方。如果你想要了解完整的內容或是想讓Ruby程式做一些神奇的事,強烈推薦去讀讀這本書。
- Metaprogramming就是讓程式去寫程式。
- Ruby語言一個很大的特性就是在執行階段時,我們仍然可以存取class的內部資訊,所以非常適合寫meta-programming。
- 一個MP的例子:ActiveRecord可以知道資料庫的table有哪些column並在model裡直接建立對應的attribute。