Created
July 18, 2013 00:35
-
-
Save jpsilvashy/6025812 to your computer and use it in GitHub Desktop.
Ruby Numeric class method for returning a letter grade as a string, takes any Numeric object, returns a string.
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
| class Numeric | |
| def to_grade | |
| case self | |
| when 97..100; grade = 'A+' | |
| when 94..96; grade = 'A' | |
| when 90..93; grade = 'A-' | |
| when 87..89; grade = 'B+' | |
| when 84..86; grade = 'B' | |
| when 80..83; grade = 'B-' | |
| when 77..79; grade = 'C+' | |
| when 74..76; grade = 'C' | |
| when 70..73; grade = 'C-' | |
| when 67..69; grade = 'D+' | |
| when 64..66; grade = 'D' | |
| when 60..63; grade = 'D-' | |
| when 0..59; grade = 'F' | |
| else grade = 'N/A' | |
| end | |
| grade | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment