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:
- 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.
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!)
Exercise: Module bundles
Exercise_: Implement has_many, belongs_to, and hasmany :through for plain ol’ Ruby objects
Homework_: Read and map out how hasmany works in ActiveRecord
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