Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created January 27, 2016 21:24
Show Gist options
  • Save cheeyeo/c7082801fe0b62ae6485 to your computer and use it in GitHub Desktop.
Save cheeyeo/c7082801fe0b62ae6485 to your computer and use it in GitHub Desktop.
Refactory Ruby case using Hashes
STUDENT_LEVELS = Hash.new(Student::Unregistered).merge(
freshman: Student::Underclassman,
sophomore: Student::Underclassman,
junior: Student::Upperclassman,
senior: Student::Upperclassman,
graduate: Student::Graduate
)
klass = STUDENT_LEVELS[params[:student_level]]
student = klass.new(name, birthdate, address, phone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment