Skip to content

Instantly share code, notes, and snippets.

@jpsilvashy
Created July 18, 2013 00:35
Show Gist options
  • Select an option

  • Save jpsilvashy/6025812 to your computer and use it in GitHub Desktop.

Select an option

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.
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