Skip to Content
Metaprogramming Ruby 2
book

Metaprogramming Ruby 2

by Paolo Perrotta
August 2014
Intermediate to advanced
250 pages
6h 20m
English
Pragmatic Bookshelf
Content preview from Metaprogramming Ruby 2

Rails Before Concern

The Rails source code has changed a lot through the years, but some basic ideas haven’t changed much. One of these is the concept behind ActiveRecord::Base. As you’ve seen in ActiveRecord::Base, this class is an assembly of dozens of modules that define both instance methods and class methods. For example, Base includes ActiveRecord::Validations, and in the process it gets instance and class methods.

The mechanism that rolls those methods into Base, however, has changed. Let’s see how it worked in the beginning.

The Include-and-Extend Trick

Around the times of Rails 2, all validation methods were defined in ActiveRecord::Validations. (Back then, there was no Active Model library.) However, Validations pulled a peculiar ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Ruby Programming Language

The Ruby Programming Language

David Flanagan, Yukihiro Matsumoto
Head First Ruby

Head First Ruby

Jay McGavren
Eloquent Ruby

Eloquent Ruby

Russ Olsen

Publisher Resources

ISBN: 9781941222751Errata Page