Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created September 25, 2018 01:36
Show Gist options
  • Save harrisonmalone/a01b10706329cabea127c134680476f5 to your computer and use it in GitHub Desktop.
Save harrisonmalone/a01b10706329cabea127c134680476f5 to your computer and use it in GitHub Desktop.
require 'pry'
require_relative 'stuff'
# this is a nice example of how to structure a terminal app functionally, using the while running loop in the menu class, and then passing an instance of a class into the route_action method so we have access to those methods
def menu
running = true
while running
display_menu
action = gets.chomp.to_i
# we create a new stuff instance which allows us to access the methods with the stuff class
stuff = Stuff.new
route_action(action, stuff)
end
end
def route_action(action, stuff)
case action
when 1 then stuff.message
when 2 then stuff.push
when 3 then stuff.create
when 4 then exit
end
end
def display_menu
puts "1. do this"
puts "2. do that"
puts "3. create stuff"
puts "4. stop"
end
# get things working
menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment