發表文章

目前顯示的是 1月, 2013的文章

ActiveRecord like API for Python

之前看到 ActiveRecord 有一個很方便的功能: find_by_COLUMN,而 COLUMN 是那個 Table 裡的 columns。這用 Ruby 的 define_method 很好實做,當然 Python 也可以做到。下面是一段 POC (Prove of Concept) code:

Monkey Patching: Python V.S. Ruby

之前在寫Rails的時候還不是很熟悉Ruby,所以很多Ruby的特性沒有去深究。最近剛考完期末考比較有時間了,所以好好來看了一下Ruby。目前覺得學Ruby的好處就是會讓我想去比較Python,因為我個人還是Python的愛好著,所以看Ruby可以做到的功能就想要看Python可不可以做到。拿Ruby最有名的名能之一來說好了: Monkey Patching,從Wikipedia: A  monkey patch  is a way to extend or modify the  run-time   code  of dynamic languages without altering the original  source code . Ruby 可以很容易的動在舊有的Class/Module中加入新的Class/Method,舉例來說我們可以新增一個  method 到 Array 中: def Array.test puts "This is a singleton method `test' of the Array class" end