Class: Drills
Direct Known Subclasses
Constant Summary
Constants included from Commands
Instance Method Summary collapse
-
#drills ⇒ Object
Determines the list of drills in this directory.
-
#linked_drills ⇒ Object
Creates a linked list from the array of drills.
-
#ordered_drills ⇒ Object
deliver drills in random order.
- #start ⇒ Object
Methods included from Commands
#back, #clear, #continue, #fail, #fold, #help, #hint, #quit, #review, #skip, #welcome, #win
Instance Method Details
#drills ⇒ Object
Determines the list of drills in this directory
43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_drills/drills.rb', line 43 def drills mod = self.class.name.gsub(/Drills/, '').downcase Dir["#{File.dirname(__FILE__)}/#{mod}/*drill.rb"].map do |f| require f name = File.basename(f, '.rb') clazz = name.split('_').map(&:capitalize).join Module.const_get(clazz).new end end |
#linked_drills ⇒ Object
Creates a linked list from the array of drills
28 29 30 31 32 33 34 35 |
# File 'lib/ruby_drills/drills.rb', line 28 def linked_drills ordered_drills.tap do |linked| for i in 0..linked.size-1 linked[i].previous = linked[i-1] unless (i == 0) linked[i].next = linked[i+1] unless (i == linked.size-1) end end end |
#ordered_drills ⇒ Object
deliver drills in random order
38 39 40 |
# File 'lib/ruby_drills/drills.rb', line 38 def ordered_drills drills.shuffle end |
#start ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby_drills/drills.rb', line 4 def start drill = linked_drills[0] while drill do drill.show begin input = Readline.readline("\n>> ", true) end while (!drill.done?(input)) case input when 'back' drill = drill.previous clear when 'menu' break else drill = drill.next continue end end end |