Created
October 26, 2011 03:31
-
-
Save burtlo/1315345 to your computer and use it in GitHub Desktop.
Superheroes In a Dish
This file contains hidden or 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
Superhero = Struct.new :name, :origin, :nemesis, :nick_name | |
SUPERHEROES = [ | |
Superhero.new("Batman", "Gotham City", "Joker", "Caped Crusader"), | |
Superhero.new("Robin", "Gotham City", "Joker", "Boy Wonder"), | |
Superhero.new("Superman", "Krypton", "Lex Luthor", "Kal El"), | |
Superhero.new("Supergirl", "Krypton", "Bizzaro", "Kara Zor-El") ] | |
def find_superheroes_with_nemesis(nemesis) | |
SUPERHEROES.find_all do |hero| | |
hero.nemesis == nemesis | |
end | |
end | |
def find_superheroes_with_origin(origin) | |
SUPERHEROES.find_all do |hero| | |
hero.origin == origin | |
end | |
end | |
all_found_superheroes = [ find_superheroes_with_nemesis("Joker"), | |
find_superheroes_with_origin("Krypton") ] | |
all_found_superheroes = all_found_superheroes.flatten | |
all_found_superheroes.each do |hero| | |
puts "hero: #{hero}\n\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment