When referring to a specific source file, I’ll give you the file’s path inside the system’s gems directory, such as gems/activerecord-4.1.0/lib/active_record.rb. If you want to explore on your own, you can use RubyGem’s unpack command to access Rails’ entire source code with a minimum of fuss. For example, gem unpack activerecord -v=4.1.0 will copy the entire distribution of Active Record 4.1.0 to the current directory.
As of version 4, Rails and its core libraries contain almost 170,000 lines of code (including white lines and comments). You can cram a lot of information into just a few lines of Ruby code—let alone hundreds of thousands. Also, you can barely find a Rails source file that doesn’t make heavy use of metaprogramming spells and other sophisticated idioms and techniques. All things considered, the Rails source code contains enough information to be intimidating.
These challenges shouldn’t stop you from browsing through this wonderful code. The Rails source code can be daunting, but it’s also chock full of interesting metaprogramming tricks. Start slowly, don’t get discouraged as you piece together the basics, and soon you might enter the growing list of Rails contributors.
Also, don’t forget the unit tests. When you’re confronted with a confusing piece of code, reach for its tests and find out how it’s supposed to be used. Once you understand their intention, most perplexing lines of code will suddenly make sense.
Now you have the Rails source code and the tools you need to explore it. In the next chapter, we’ll dive into the first stop on our tour: a quick look at Active Record, the most iconic of the Rails components.