9 on Menu 7/13 need help understanding this line... Ruby final project


#1
if __FILE__ == $PROGRAM_NAME
  include Menu
  include Promptable
  my_list = List.new
  puts 'Please choose from the following list'
    until ['q'].include?(user_input = prompt(show).downcase)
    end
end

THIS LINE: until ['q'].include?(user_input = prompt(show).downcase)

1) is it implied that include? is referring to the user input string? how does this line know you are talking about the user input?

2) so user_input is just a variable we are making or is it a reserved ruby word?

3) with promp(show) i don't understand how this ties together. show isnt even in the prompt method or the promptable module at all. There is a show method in the menu module and the list class... im so lost .

can someone please try to explain this in a very easy way? my head hurts lol

here is my code...

module Menu

def menu
puts "Welcome User"
puts "Todo List Option "
puts "1) Add"
puts "2) Show"
puts "Q) Quit"
end

def show

menu

end
end

module Promptable

 def prompt(message = 'What would you like to do?', symbol = ':> ')
  print message
  print symbol
  gets.chomp
end

end

class List
attr_reader :all_tasks

creates an array instance to handle all tasks

def initialize

@all_tasks = []
end

def add(task)

all_tasks << task

end

def show

	all_tasks.each do |x| puts x.description 

	end 
	end

end

class Task
# makes an instance readable to a user but not writable
attr_reader :description

# creates an instance of a task
def initialize(description)

@description = description
end

end

# this makes a file identifiable if ran from the command line or from another 
# ruby file _file_ = todo.rb and $PROGRAM_NAME are the same thing where as 
# todo.rb = file and program name draws internally what the program name is 
# automatically

if FILE == $PROGRAM_NAME
include Promptable
include Menu
my_list = List.new
puts " Please choose from the following list"
until ['q'].include?(user_input = prompt(show).downcase)
end
end


#2

I had the same problem as you but I managed to understand it after a bit of experimentation.

  1. is it implied that include? is referring to the user input string? how does this line know you are talking about the user input?

[‘q’].include? - This is asking to check if the letter ‘q’ is in the variable user_input. Alternatively it can be ‘q’.include?. For example [‘q’].include?(q) == True

  1. so user_input is just a variable we are making or is it a reserved ruby word?
    user_input is a variable we are making

  2. with promp(show) i don’t understand how this ties together. show isnt even in the prompt method or the promptable module at all. There is a show method in the menu module and the list class… im so lost .

To break it down:
show = puts “Welcome User”
puts "Todo List Option "
puts “1) Add”
puts “2) Show”
puts “Q) Quit”

prompt(show) is storing ‘show’ as a message. So when we get to the line ‘print message’ it is printing the above! And then it prints the default value for symbol which is “=>”. Finally it prompts the user to enter a value, when this value is entered it is returned by the method, user_input = prompt(show).

def prompt(message='What would you like to do?', symbol=':>')
	print message #Prints show
	print symbol #Prints ':>'
	gets.chomp #takes user input and returns value as it is the last command in the method
    end

I know this is late but wanted to help others with similar problem.

Happy Coding!


#3