このサイトは、メタプログラミングRuby 第2版を読んだ人向けの練習用クイズです。本を読んだだけだとなかなか身につかないRubyのメタプログラミングの知識を、手を動かして理解することを目的にしています。
各クイズには仕様が書かれているので、メタプログラミングを駆使して仕様を満たすコードを書いてください。仕様を満たしているかどうかはテストを実行することでわかります。利用できるRubyのバージョンは3.4です。
クイズはセクションで分かれています。セクションは02_object_model
のように、頭に番号が割り当てられています。この番号はメタプログラミングRuby 第2版の章番号に該当します。つまり02_object_model
セクションであれば本の2章で学んだ内容を問うクイズになります。00_setup
はクイズを解くことを練習するための問題です。
注意事項: 一部の問題はその問題に対応する章よりも後に書かれている機能を知らないと解けないもしくは解きづらいものがあるので、とりあえず6章までざっと通読した上で問題に取り掛かるのがいいかと思います。
どうしてもテストを通すことができなかった場合は回答例を見ることができます。回答例を参考にしつつ書籍を読み直すことで、メタプログラミングについての理解がより深まっていくことでしょう。
このサイトのコードは https://github.com/willnet/try-metaprogramming-ruby で管理されています。
This site is a practice quiz for people who have read Metaprogramming Ruby 2nd Edition. It aims to help you understand Ruby metaprogramming knowledge through hands-on practice, which can be difficult to grasp just by reading the book.
Each quiz has specifications written for it, so please write code that meets the specifications by making full use of metaprogramming. You can determine whether the specifications are met by running tests. The available Ruby version is 3.4.
The quizzes are divided into sections. Sections are assigned numbers at the beginning, like 02_object_model
. This number corresponds to the chapter number in Metaprogramming Ruby 2nd Edition. In other words, the 02_object_model
section contains quizzes about the content learned in Chapter 2 of the book. 00_setup
is a practice problem for learning how to solve quizzes.
Note: Some problems cannot be solved or are difficult to solve without knowing features that are described later in the book than the chapter corresponding to that problem, so we recommend reading through to Chapter 6 first before tackling the problems.
If you cannot pass the tests no matter what, you can view the answer examples. By referring to the answer examples and re-reading the book, you will deepen your understanding of metaprogramming.
The code for this site is managed at https://github.com/willnet/try-metaprogramming-ruby.