Scotland on Rails Charity tutorial
C Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


The Secret Ingredients of Ruby

This is material we’re preparing for an all-day pre-conference charity tutorial for Scotland on Rails to benefit the Children’s Hospice Association of Scotland.


These things make Ruby special. They aren’t “advanced”. They’re fundamental:

  1. Blocks/closures
  2. Object-oriented vs. class-oriented (classes are less important than other languages, using mixins instead of inheritance, etc.)
  3. Class definitions are active (method calls in class scope, etc.)
  4. Hooks, callbacks, and reflection

Each of these four areas has an exercise and a homework project. The exercise is something that can be done in 30 minutes at the tutorial. The homework project is harder and probably involves reading some specific code.

Blocks and closures

Exercise: Ruby-based configuration:

configuration = configure do |config|
  config.tail_logs = true
  config.max_connections = 55
  config.admin_password = 'secret'_
  config.app_server do |app_server_config|
    app_server_config.port = 8808
    app_server_config.admin_password = config.admin_password

configuration.class # => Configuration
configuration.tail_logs # => true
configuration.app_server.admin_password # => 'secret'

Extra Credit_: Look through all of the classes built into Ruby (or in the standard library) and find an interesting use of toproc (and implement it!)

Object Orientation and Mixins

Exercise: Module bundles

Class definitions are active

Exercise_: Implement has_many, belongs_to, and hasmany :through for plain ol’ Ruby objects

Homework_: Read and map out how hasmany works in ActiveRecord

Hooks, callbacks, and reflection

Exercise_: OpenConst (constmissing + OpenStruct)?

Extra Credit: method

Homework: Implement your own clone of Jim Weirich’s Builder library


  • Marcel Molina, Jr.
  • Chad Fowler

h1. Thanks

  • Mike Clark contributed ideas for the structure of the tutorial
  • Dave Thomas taught Chad a lot of this stuff
  • Alan Francis roped us into doing this tutorial and organized the conference