(English to follow after Japanese).
これまでプラグイン関係の情報をネットで探したり、プラグインづくりに必要なRuby テクニックを色々読んでいたのですがようやく「これだ」という一冊を見つけました。
その名もずばり”Rails Plugins – Extending Rails Beyond the Core”.
私がいくつかのプラグインのソースを読んでいてよくわからなかったのが、モジュールが何層にも入れ子になっているところだったのですが、この本では、プラグインの一番シンプルな形を最初に紹介し、そこから徐々にActive RecordやController, Viewを拡張する形で順をおって複雑な拡張の仕方を説明してくれているのでわかりやすかったです。
もし以下のようなコードに以前でくわして、なにを意味するかわからない方は一読をおすすめします。
module ModuleName
module ClassMethods
end
extend ClassMethods
def self.included(receiver)
receiver.extend(ClassMethods)
end
end
self.includedの部分はRuby For Railsにも出ていたのですが、この本を読むまでどういう用途につかえば良いのかいまいちわかっていませんでした。
Addison Wesleyのショートカットシリーズは150ページぐらいの少量なので、英語がにがてなかたも比較的取っ付きやすいと思います。
私は5月の連休(イギリスは日本より格段と祝日が少ないのですが、5月は珍しく3連休が2度あります)を利用して一気に読み終わりました。
来週からはたくさんのプラグインのソースコードを読んでいきたいです。
I’ve spent quite a while looking for plugin related resources on net, but I finally found the one.
This e-book is called “Rails Plugins – Extending Rails Beyond the Core”, and it’s entirely dedicated to Rails plugin and it’s exactly what I was looking for.
I mentioned earlier that I did not understand why there are so many nested modules in plugins.
This book started from the simplest example with no modules, then explained more detailed ones step by step.
If you encountered this kind of syntax when you read some source code and did not know what it means, the answer is in the book.
module ModuleName
module ClassMethods
end
extend ClassMethods
def self.included(receiver)
receiver.extend(ClassMethods)
end
end
I actually encountered this when I was reading “Ruby For Rails” , book , but did not know the right usage untill I read this book.
Addison Wesley’s shortcut is very small ebook, so I was able to finish reading using this long weekend (it’s not as long as Japan’s “Golden week” though).
My next goal is to read many plugin source code.
