So far, we have seen:
- A basic overview of metaprogramming
- How we can use it in a custom class
- How to use it on existing Ruby classes, such as the String class
In this section, we are going to see how metaprogramming can be used in real-world applications.
I'm going to open up a Ruby on Rails application because Rails leverages metaprogramming as well as any program I've ever seen. We're going to walk through how the Rails framework generates database lookup methods on the fly.
Here is the database schema file for the Rails application we're going to look at:
create_table "contacts", force: true do |t|
t.string "name"
t.string "email"
t.text "message"
t.string "category"
t.datetime "created_at"
t.datetime "updated_at"
end...