Skip to content

Instantly share code, notes, and snippets.

@zeevallin
Created July 4, 2013 00:57
Show Gist options
  • Save zeevallin/5924113 to your computer and use it in GitHub Desktop.
Save zeevallin/5924113 to your computer and use it in GitHub Desktop.
class Animal
attr_accessor :name
def self.named(name)
self.new(name)
end
def initialize(name)
self.name = name
end
def make_noise
puts "#{name} says #{sound}"
end
def sound
""
end
end
class Kitten < Animal
def sound
"meow!"
end
end
class Human < Animal
def sound
"ouch!"
end
end
class AnimalCannon
attr_accessor :target, :ammunition
def self.load(target: nil, ammunition: nil)
self.new(target,ammunition)
end
def initialize(target,ammunition)
@target = target
@ammunition = ammunition
end
def fire
puts "Cannon fires the #{ammunition.class.to_s.downcase} named #{ammunition.name}."
ammunition.make_noise
sleep 3
target.make_noise
end
end
[ Kitten.named("Bill"), Kitten.named("Bull") ].each do |kitten|
AnimalCannon.load(target: Human.named("Zeeraw"), ammunition: kitten).fire
end
Copy link

ghost commented Jul 4, 2013

zeeraw what

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment