Created
September 25, 2018 01:36
-
-
Save harrisonmalone/a01b10706329cabea127c134680476f5 to your computer and use it in GitHub Desktop.
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
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