Every repository with this icon (
Every repository with this icon (
tree 09577c46591ef56e4969ad440ccb949592a39ab2
parent 0a911fe0823bcbfc2b1cc37b865e3c9c097a1cc4
| name | age | message | |
|---|---|---|---|
| |
README.textile | ||
| |
blocks/ | ||
| |
class_definitions_are_active/ | ||
| |
exercises/ | ||
| |
hooks_callbacks_reflection/ | ||
| |
object_orientation/ |
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:
- Blocks/closures
- Object-oriented vs. class-oriented (classes are less important than other languages, using mixins instead of inheritance, etc.)
- Class definitions are active (method calls in class scope, etc.)
- 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








