Metaprogramming Terminators

Readme Homework

Episode 10 - Meta Terminator

Meta Programming in Ruby

#class GoodTerminator
#  likes_to_protect [:john_connor, :sarah_connor]
#  likes_to_destroy []
#class BadTerminator
#  likes_to_protect []
#  likes_to_destroy [:john_connor, :sarah_connor]

Panda Level

  1. Implement a method "protects?" where you can pass in the name of a person to check if he protects them
  2. Create a method in the Terminatorable module called "good?" that will tell if a Terminator is good or bad
  3. Create a spec that if the Terminator is trying to destroy someone, they are bad

Tiger Level

  1. Create the GoodTerminator and BadTerminator classes
  2. Update the specs to test the GoodTerminator and Bad Terminator

Eagle Level

  1. Split the methods into likes_to_protect and likes_to_destroy
  2. Alternatively, rename to configuration that accepts a hash of people to protect and people to destroy


Copyright: 2012 Jesse Wolgamott, MIT License (See LICENSE)

Metaprogramming Terminators

  • Area:

  • Runtime:

  • Tech:

  • Tags:

    RSpec meta eval  

OK, so if you've heard of Ruby described as "powerful" it's because of the ability to change and morf itself at runtime. We call this "Meta Programming" and is pretty unique.

This week, we delve into Meta Programming and try to create a Terminator that can either be good or evil, depending on which movie he's starring in.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


Ruby Off Rails is dedicated to accelerating the mastering of Ruby and increasing developer happiness everywhere.

In my software training, I see two distinct sets of programmers: those who know Ruby, and those who haven’t learned it yet. People who learn Ruby have an easier time understanding Rails, gems, and what magic voodoo is going on. And most importantly, they can cast wicked voodoo themselves.