O'Reilly logo

Advanced Rails by Brad Ediger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. ActiveSupport and RailTies

[Programs] must be written for people to read, and only incidentally for machines to execute.

—H. Abelson and G. Sussmann

Structure and Interpretation of Computer Programs, MIT Press, 1985

We continue in our bottom-up view of Rails by examining the pieces that form the basis for Rails. ActiveSupport is a library that provides generic, reusable functions that are not specific to any one part of Rails. We can use many of these methods ourselves when writing our application code. RailTies is the other half, containing parts that glue Rails together in a Rails-specific way. Although we will not usually use RailTies functions in our own code, it is important and instructive to examine them.

Most of this chapter is nonsequential; feel free to skip around. However, in accordance with our bottom-up approach to Rails, later chapters will build on this material.

Ruby You May Have Missed

It is very easy to overlook some of Ruby’s more useful methods. The best way to find them is to read code. Here are some of the more obscure, but helpful, ones.

Array

  • Array#* an operate as Array#join (if given a string or stringlike argument); it also does repetition:

    	[1, 2, 3] * "; " # => "1; 2; 3"
    
    	[0] * 5 # => [0, 0, 0, 0, 0]
  • Array#pack and String#unpack are useful for working with binary files. why the lucky stiff uses Array#pack to stuff a series of numbers into a BMP-formatted sparkline graph without any heavy image libraries, in 13 lines of code (http://redhanded.hobix.com/inspect/sparklinesForMinimalists.html ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required