Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

50 | Chapter 2: ActiveSupport and RailTies


questions of it while it is running. There are some methods to find information via
static examination of the code, though:



  • A good text editor will help you cull through large amounts of source.
    — TextMate (http://macromates.com/) is the semi-official editor of the Ruby on
    Rails core team. It has great facilities for search (including search by regular
    expressions) and comes with some pretty impressive Ruby and Rails features. It
    supports projects (entire source trees managed as one unit). However, it is
    available for Mac OS X only and costs 39 at the time of this writing.
    — Vim (http://vim.org/) is an incredible open source text editor available for
    just about every platform. It has a long learning curve, but it is extremely
    powerful. If you use Vim with Rails, do yourself a favor and install the vim-
    ruby package (http://rubyforge.org/projects/vim-ruby/).

  • In conjunction with a good text editor, you should familiarize yourself with
    command-line tools for text processing. Regular expressions (used with the tool
    of your choice such as sed, Perl, or egrep) provide a more powerful query lan-
    guage for finding patterns within large bodies of source.

  • Search the Web. The popularity of Rails has created a fury of bloggers who write
    about Ruby and Rails, and they usually fill in the gaps where the official docu-
    mentation is lacking. Google Code Search*indexes thousands of open source
    projects, and has useful features such as search by regular expression.


Reading the Call Stack


Most Rails developers are familiar with reading a stack trace when debugging excep-
tions. It can be very helpful to know the sequence in which framework and applica-
tion functions were called when something goes wrong. But what if we are just
curious? It doesn’t make sense to raise an exception just to generate a readable back-
trace. Luckily, we have some tools at our disposal to analyze the call stack in run-
ning code, nondestructively.


The first such tool is Ruby’s standardKernel#callermethod, which gives us a sim-
ple backtrace as an array of strings:


#!/usr/local/bin/ruby1.8.4

# use the pretty-printer; call stacks can be huge
require 'pp'

class Test
def foo
bar
end

*http://www.google.com/codesearch

Free download pdf