Module: Commands
- Included in:
- Drill, Drills, Starter, WelcomeDrills
- Defined in:
- lib/ruby_drills/commands.rb
Constant Summary collapse
- GAMBLER =
File.read(File.join(File.dirname(__FILE__), 'data/gambler.ascii'))
Instance Method Summary collapse
- #back ⇒ Object
- #clear ⇒ Object
-
#continue ⇒ Object
Each command returns a response indicating whether or not the drill is complete.
- #fail(input, message = nil) ⇒ Object
- #fold ⇒ Object
- #help ⇒ Object
- #hint ⇒ Object
- #quit ⇒ Object
- #review ⇒ Object
- #skip ⇒ Object
- #welcome ⇒ Object
- #win(input) ⇒ Object
Instance Method Details
#back ⇒ Object
51 52 53 54 |
# File 'lib/ruby_drills/commands.rb', line 51 def back puts "\tYou're already at the first drill".yellow if !previous previous end |
#clear ⇒ Object
56 57 58 59 |
# File 'lib/ruby_drills/commands.rb', line 56 def clear system('clear') false end |
#continue ⇒ Object
Each command returns a response indicating whether or not the drill is complete.
5 6 7 8 9 10 |
# File 'lib/ruby_drills/commands.rb', line 5 def continue puts "\nPress any key to continue:" Chomper.get_char system('clear'); true end |
#fail(input, message = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/ruby_drills/commands.rb', line 12 def fail(input, =nil) puts "\n\tnot yet...".yellow RubyDrills::Config::SESSIONS.attempt(self.class.name, input, reference, 'fail') puts .yellow unless .nil? false end |
#fold ⇒ Object
40 41 42 43 44 |
# File 'lib/ruby_drills/commands.rb', line 40 def fold puts GAMBLER puts "\nYou got to know when to hold 'em, know when to fold 'em...\n".yellow true end |
#help ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ruby_drills/commands.rb', line 61 def help puts %{ For each drill, type in some Ruby. Answer correctly and you'll get a 'WIN' on the board. Otherwise, you'll see 'not yet'. These commands are also available to you: help:\tthis screen show:\tshow the problem description hint:\tget unstuck back:\tback to the previous drill skip:\ton to the next drill review:\tsee the answer clear:\tclear the screen menu:\tback to the main menu exit:\tend your session} false end |
#hint ⇒ Object
46 47 48 49 |
# File 'lib/ruby_drills/commands.rb', line 46 def hint puts hints.rotate!.last false end |
#quit ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ruby_drills/commands.rb', line 95 def quit system('clear') puts %{ Mastery...the mysterious process during which what is at first difficult becomes progressively easier and more pleasurable through practice. --- George Leonard} puts exit end |
#review ⇒ Object
34 35 36 37 38 |
# File 'lib/ruby_drills/commands.rb', line 34 def review puts "\n\t#{reference}".green puts "\n\ttry this one again soon...".yellow true end |
#skip ⇒ Object
29 30 31 32 |
# File 'lib/ruby_drills/commands.rb', line 29 def skip puts "\n\tskipping...for now...".yellow true end |
#welcome ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ruby_drills/commands.rb', line 81 def welcome puts %{ Welcome to Ruby Drills! Drills are a way to engage in deliberate practice to master a language. Challenges in Ruby Drills focus on a specific method. Answers typically consist of a single line. Your objective is to complete the drill with ease and joy, without consulting any external documentation. ----------------------------------------------------------------------- } end |
#win(input) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_drills/commands.rb', line 19 def win(input) puts "\n\t!!! WIN !!!\n".green RubyDrills::Config::SESSIONS.attempt(self.class.name, input, reference, 'pass') if (reference != input.strip) puts "How does your answer compare to the reference solution?" puts reference end true end |