2008年12月18日 星期四

alias_method_chain

alias_method_chain

alias_method A, B 有點就是 B 把function copy 一份到B

Encapsulates the common pattern of:
這就像是foo 沒改feature之前 copy 一份 所以叫做 foo_without_feature
然後弄了個function 叫做foo_with_feature 然後蓋掉 foo
之後叫foo 就是有feature的 foo_with_feature

With this, you simply do:
And both aliases are set up for you.

Query and bang methods (foo?, foo!) keep the same punctuation:
is equivalent to
so you can safely chain foo, foo?, and foo! with the same feature.

沒有留言: