Skip to content

Instantly share code, notes, and snippets.

@Martin-Nyaga
Created November 24, 2016 15:50
Show Gist options
  • Save Martin-Nyaga/9d88f2f3a8c2da972d903cbd34d180ff to your computer and use it in GitHub Desktop.
Save Martin-Nyaga/9d88f2f3a8c2da972d903cbd34d180ff to your computer and use it in GitHub Desktop.
class TicketFactory
TICKET_CLASSES = {
'Truck' => TruckParkingTicket,
'Matatu' => MatatuParkingTicket,
'Public Bus' => PublicBusParkingTicket
}
def self.ticket_for opts
# .fetch takes a second argument as a default if the
# key is not found
TICKET_CLASSES.fetch(opts[:vehicle_type], ParkingTicket).new(opts)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment