-
Notifications
You must be signed in to change notification settings - Fork 24
Email: [email protected]
Email: [email protected]
#Charly and I did the first 3 together in class, and I finished the rest on my own (this is Aaron's file)
#1. What is the first pokemon in our database? Our last one?
Pokemon.first Pokemon.last
#2. Are any pokemon palindromes? If so, which ones?
names = Pokemon.all; names.select {|pmon| pmon.name.downcase == pmon.name.downcase.reverse}
#3. Find all pokemon that are GHOST type.
Pokemon.where(:poke_type => "GHOST")
#4. Are there more pokemon with even pokemon numbers who are GRASS type or who are FIRE type?
names = Pokemon.all; newnames = names.select {|pmon| pmon.poke_type == "GRASS"}; newestnames = newnames.select{|pman| pman.id%2 == 0}; firenames = names.select {|pmon| pmon.poke_type == "FIRE"}; newfirenames = firenames.select{|pman| pman.id%2 == 0}; grasssize = newestnames.size firesize = newfirenames.size grasssize if grasssize > firesize puts "More GRASS type with even number" else puts "More FIRE type with even number" end
#5. Try to defeat Charizard. Find a pokemon with special attack (sp_attack) greater than 78 and whose type is water.
Waterpoke = Pokemon.where(:poke_type => "WATER"); Waterpoke.where("sp_atk > ?", 78)
#6. Pokemon can no longer have over 100 health (hp). Update any pokemon who has health greater than 100 to have only 99 health (hp).
names = Pokemon.all; superhealth = names.select {|el| el.hp > 100}; superhealth.each {|el| el.hp = 99}; superhealth.each {|el| el.save};
#7. Make a new pokemon. What attributes are necessary? What attributes do you want to make sure you put in?
Pokemon.create(id: 204, poke_num: 204, name: "Shablam", poke_type: "AWESOME", hp: 50, attack: 200, defense: 20, sp_atk: 300, sp_def: 50, speed: 400);
#8. Everyone hates Jigglypuff. Remove that pokemon from the database (and existance!). Make sure it's not just removed from Rubyland, but also from Databaseland.
jigglypuff = Pokemon.where(:name => "Jigglypuff"); jigglypuff.destroy(jigglypuff);
- Home
- Assignments
- Resources
- Piazza
- Last Summer's Wiki-Curriculum
- Code Examples from Class are in this course repository