1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env ruby

class Human
  def initialize(name)
    @name = name
  end
  
  def special
    puts "#{@name} is normal, no special abilities."
  end
  alias_method :abilities, :special
end

module SuperPower
  attr_accessor :powers
  def special
    unless @powers
      super 
    else
      puts "#{@name} is a hero - he/she can #{@powers}"
    end
  end
  alias_method :abilities, :special
end

class Hero < Human
  include SuperPower
end

class BadGuy < Human
  include SuperPower
end

mohinder = Human.new('Mohinder')
mohinder.special   # Mohinder is normal, no special abilities.
mohinder.abilities # Mohinder is normal, no special abilities.

peter = Hero.new('Peter Petrelli')
peter.powers = "mimic the powers of other heroes nearby, fly, and read minds"
peter.special   # Peter Petrelli is a hero - he/she can mimic the powers of other heroes nearby, fly, and read minds
peter.abilities # Peter Petrelli is a hero - he/she can mimic the powers of other heroes nearby, fly, and read minds

sylar = BadGuy.new('Sylar')
sylar.powers = "steal powers from other heroes, telekinetics, and super-hearing"
sylar.special   # Sylar is a hero - he/she can steal powers from other heroes, telekinetics, and super-hearing
sylar.abilities # Sylar is a hero - he/she can steal powers from other heroes, telekinetics, and super-hearing

hrg = Hero.new('Horn-Rimmed Glasses')
hrg.special   # Horn-Rimmed Glasses is normal, no special abilities.
hrg.abilities # NoMethodError: super: no superclass method ‘special’