Skip to content

Instantly share code, notes, and snippets.

@knoxjeffrey
Created December 11, 2014 12:43
Show Gist options
  • Save knoxjeffrey/e2832abd231d51aac8db to your computer and use it in GitHub Desktop.
Save knoxjeffrey/e2832abd231d51aac8db to your computer and use it in GitHub Desktop.
module while loop
module Text
def self.print_string(text)
puts "\n*** #{text} ***"
end
def self.chomp_it
gets.chomp
end
end
module Validate
def self.valid_choice?(choice)
if ['p', 'r', 's'].include?(choice.downcase)
true
else
print_string "Enter a valid choice. Please try again"
end
end
def self.valid_decision?(the_decision)
if ['y', 'n'].include?(the_decision.downcase)
return true
else
print_string "You must enter Y or N. Please try again"
end
end
end
begin
Text.print_string "Choose one: P/R/S"
choice = Text.chomp_it
end while !Validate.valid_choice?(choice)
*** Choose one: P/R/S ***
as
NoMethodError: undefined method `print_string' for Validate:Module
from (irb):16:in `valid_choice?'
from (irb):40
from /Users/knoxjeffrey/.rvm/rubies/ruby-2.0.0-p598/bin/irb:12:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment