Created
May 25, 2015 00:09
-
-
Save anonymous/7054c31531a9afa5a82b to your computer and use it in GitHub Desktop.
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 Student | |
attr_accessor :scores, :first_name | |
def initialize(student = {}) | |
@scores = student["scores"] | |
@first_name = student["first_name"] | |
end | |
def average_score | |
scores.inject{|sum, score| sum + score} / scores.length | |
end | |
def letter_grade(grade = self.average_score) | |
lookup_letter_grade = {10 => "A", 9 => "A",8 => "B", 7 => "C", 6 => "D"} | |
if grade < 60 | |
return "F" | |
else | |
return lookup_letter_grade[grade / 10] | |
end | |
end | |
end | |
students = Array.new | |
students << Array.new(1){Student.new("scores" => [100,100,100,0,100], "first_name" => "Alex")} | |
students << Array.new(1){Student.new("scores" => [100,100,100,0,100], "first_name" => "Penelope")} | |
students << Array.new(1){Student.new("scores" => [100,100,100,0,100], "first_name" => "Ninja")} | |
students << Array.new(1){Student.new("scores" => [100,100,100,0,100], "first_name" => "Rainbow")} | |
students << Array.new(1){Student.new("scores" => [100,100,100,0,100], "first_name" => "Cloud Rider")} | |
p students[0].first_name == "Alex" | |
p students[0].scores.length == 5 | |
p students[0].scores[0] == students[0].scores[4] | |
p students[0].scores[3] == 0 |
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
line 34 <main>': undefined method `first_name' for #<Array:0x007f83f2161e80> (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment