Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created October 26, 2011 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burtlo/1315345 to your computer and use it in GitHub Desktop.
Save burtlo/1315345 to your computer and use it in GitHub Desktop.
Superheroes In a Dish
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