Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Scotland on Rails Charity tutorial

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 blocks
Octocat-spinner-32 class_definitions_are_active
Octocat-spinner-32 exercises
Octocat-spinner-32 hooks_callbacks_reflection
Octocat-spinner-32 object_orientation
Octocat-spinner-32 README.textile
README.textile

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.

Contents

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
  end
end

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

Authors

  • 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
Something went wrong with that request. Please try again.