Module: Mathangman::Utility
- Included in:
- Game
- Defined in:
- lib/mathangman/utility.rb
Instance Method Summary collapse
- #check_source(addy) ⇒ Object
- #is_alpha?(char) ⇒ Boolean
- #quit_reply(obj = nil) ⇒ Object
- #quitter(obj = nil) ⇒ Object
- #save_on_quit(obj) ⇒ Object
Instance Method Details
#check_source(addy) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mathangman/utility.rb', line 38 def check_source(addy) address = File.join(File.dirname(File.(__FILE__)))[0..-15] + addy # require "pry"; binding.pry if File.exist?(address) # require "pry"; binding.pry dict = File.readlines address new_dict = [] dict.each { | item | new_dict << item.to_s } new_dict else # p "hello" puts Display.no_source exit end end |
#is_alpha?(char) ⇒ Boolean
55 56 57 58 59 60 61 |
# File 'lib/mathangman/utility.rb', line 55 def is_alpha?(char) if char.length > 1 true if char.match(/^[[:alpha:]]+$/) != nil else true if char.match(/^[[:alpha:]]$/) != nil end end |
#quit_reply(obj = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mathangman/utility.rb', line 16 def quit_reply(obj = nil) reply = gets.chomp.downcase if reply == "y" || reply == "yes" if obj != nil && obj != "pre_game" puts Display.save_notice save_on_quit(obj) end elsif reply != "y" && reply != "yes" && obj == "pre_game" puts " * Choose a difficulty level to continue. *" obj.check_difficulty elsif reply != "y" && reply != "yes" && obj != "pre_game" && (is_alpha? reply) obj.guesses end end |
#quitter(obj = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mathangman/utility.rb', line 5 def quitter(obj = nil) if obj == "force" exit else puts Display.confirm_quit quit_reply(obj) puts Display.quit_notice exit end end |
#save_on_quit(obj) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mathangman/utility.rb', line 31 def save_on_quit(obj) save_it = gets.chomp.downcase if save_it == 'y' || save_it == "yes" obj.save_game end end |