Any ideas for compacting this code down?
I've done this as an exercise in loops. Can anyone suggest ways of compacting it down? test2.rb: def main pick go again end test.rb require 'colorize' def again if $i == $p puts msg(2) # Would you like to go again? answer = gets.downcase.chomp.to_s if answer == "yes" main # Go back to the beginning else msg(4) # Are you sure? confirm = gets.downcase.chomp.to_s case confirm when "yes" msg(3) # Ok then, thanks for playing when "no" main # Go again else msg(5) # Msg for unrecognisable input end end else puts msg(3) # Ok then, thanks for playing end end def pick msg(6) $p = gets.chomp.to_i end def go $i = 0 while $i < $p msg(1) input options sum $i += 1 #count end end def sum a = $p - $i - 1 if a >= 0 puts "You have #{a} goes left..." else again end end def input @b = gets.chomp.to_i end def options if @b <= $p @b elsif @b > $p puts "#{@b}".red + " is too large!".white puts "Try again!" go else puts "Wrong! Try again" go end end def msg(n) case n when 1 puts "Choose a number between 1 and #{$p}".red when 2 puts "Would you like to go again?" when 3 puts "OK then, thanks for playing!" when 4 puts "Are you sure? Yes/No?" when 5 puts "I really don't know what you want from me. I'll assume you don't want to play. Goodbye!" when 6 puts "Pick a number... ".blue end end def count puts "i = #{$i}" end