Created
May 1, 2013 05:01
-
-
Save meaganewaller/5493818 to your computer and use it in GitHub Desktop.
./example.rb:42: Use RbConfig instead of obsolete and deprecated Config. When running. Any insight to this?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Magical | |
def power | |
puts 'certain power a magical being would have' | |
end | |
end | |
class Wizard < Magical | |
def power | |
puts 'The Ground Starts to Shake' | |
end | |
end | |
class Dragon < Magical | |
def power | |
puts 'Flames Appear All Around' | |
end | |
end | |
class Person | |
attr_accessor :name | |
def initialize(name) | |
@dead = false | |
@name = name | |
end | |
def kill!(by = nil) | |
puts "No one dares mess with me, #{name}" | |
puts "Oh, no! My only weakness, a #{by.class}" if by | |
puts | |
@dead = true | |
end | |
def dead? | |
@dead | |
end | |
end | |
module Fight | |
def self.apply_to_all_magicals | |
magical_classes = Module.constants.map { |x| | |
Module.const_get(x) }.select { |x| | |
x.respond_to?(:superclass) && x.superclass == Magical } | |
magical_classes.each do |magical_class| | |
magical_class.module_eval do | |
include Fight | |
end | |
end | |
end | |
def battle(person) | |
power | |
puts "The Sky Goes Grey, Ominious Music is Heard" | |
person.kill!(self) | |
power | |
puts | |
end | |
end | |
wizard = Wizard.new | |
dragon = Dragon.new | |
people = [Person.new('The Great and Powerful Fred'), Person.new('The Not So Great and Way Less Powerful Ted')] | |
begin | |
wizard.battle(people[0]) | |
rescue => e | |
puts 'I can defeat anything, well except for my one weakness...' | |
end | |
begin | |
dragon.battle(people[0]) | |
rescue => e | |
puts "No one shall know my one weakness" | |
end | |
puts | |
# not so fast | |
Fight.apply_to_all_magicals | |
wizard.battle(people[0]) | |
dragon.battle(people[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment