Class: Drill

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/ruby_drills/drill.rb

Constant Summary

Constants included from Commands

Commands::GAMBLER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#back, #clear, #continue, #fail, #fold, #help, #hint, #quit, #review, #skip, #welcome, #win

Constructor Details

#initializeDrill

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

#hintsObject

Returns the value of attribute hints.



3
4
5
# File 'lib/ruby_drills/drill.rb', line 3

def hints
  @hints
end

#nextObject

Returns the value of attribute next.



3
4
5
# File 'lib/ruby_drills/drill.rb', line 3

def next
  @next
end

#previousObject

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

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_drills/drill.rb', line 19

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

#drillsObject



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

#expectedObject



15
16
17
# File 'lib/ruby_drills/drill.rb', line 15

def expected
  eval(reference)
end