Class: Drill
Direct Known Subclasses
AllDrill, AllNamesDrill, ChompDrill, ChunkDrill, DeleteDrill, DropWhileDrill, GroupByDrill, GsubDrill, IncludeDrill, MapDrill, MergeDrill, PartitionDrill, ReduceDrill, RejectDrill, SplitDrill, SqueezeDrill, TakeWhileDrill, ToSymDrill, ZipDrill
Constant Summary
Constants included from Commands
Instance Attribute Summary collapse
-
#hints ⇒ Object
Returns the value of attribute hints.
-
#next ⇒ Object
Returns the value of attribute next.
-
#previous ⇒ Object
Returns the value of attribute previous.
Instance Method Summary collapse
- #done?(input) ⇒ Boolean
- #drills ⇒ Object
- #expected ⇒ Object
-
#initialize ⇒ Drill
constructor
A new instance of Drill.
- #non!(method, input) ⇒ Object
Methods included from Commands
#back, #clear, #continue, #fail, #fold, #help, #hint, #quit, #review, #skip, #welcome, #win
Constructor Details
#initialize ⇒ Drill
Returns a new instance of Drill.
5 6 7 8 |
# File 'lib/ruby_drills/drill.rb', line 5 def initialize setup @context = Pry.binding_for(self) end |
Instance Attribute Details
#hints ⇒ Object
Returns the value of attribute hints.
3 4 5 |
# File 'lib/ruby_drills/drill.rb', line 3 def hints @hints end |
#next ⇒ Object
Returns the value of attribute next.
3 4 5 |
# File 'lib/ruby_drills/drill.rb', line 3 def next @next end |
#previous ⇒ Object
Returns the value of attribute previous.
3 4 5 |
# File 'lib/ruby_drills/drill.rb', line 3 def previous @previous end |
Instance Method Details
#done?(input) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_drills/drill.rb', line 31 def done?(input) case input.to_sym when :menu RubyDrills::Config::SESSIONS.command(self.class.name, input) clear true when :exit RubyDrills::Config::SESSIONS.command(self.class.name, input) quit when :show RubyDrills::Config::SESSIONS.command(self.class.name, input) show when lambda {|s| Commands.instance_methods.include?(s) } RubyDrills::Config::SESSIONS.command(self.class.name, input) self.send(input) else check_answer(input) end end |
#drills ⇒ Object
10 11 12 13 |
# File 'lib/ruby_drills/drill.rb', line 10 def drills # Composite pattern: Allow for drill.start to work in the REPL or in tests. [self] end |
#expected ⇒ Object
15 16 17 |
# File 'lib/ruby_drills/drill.rb', line 15 def expected eval(reference) end |
#non!(method, input) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_drills/drill.rb', line 19 def non!(method, input) if (input.include?('!')) puts "\n\tAvoid using ! methods that modify their receiver...".red # We need to rerun setup since the user changed the state of # the drill. setup return false end input.include?(method) end |