Class: ChunkDrill
- Inherits:
-
Drill
show all
- Defined in:
- lib/ruby_drills/array/chunk_drill.rb
Constant Summary
Constants included
from Commands
Commands::GAMBLER
Instance Attribute Summary
Attributes inherited from Drill
#hints, #next, #previous
Instance Method Summary
collapse
Methods inherited from Drill
#done?, #drills, #expected, #initialize, #non!
Methods included from Commands
#back, #clear, #continue, #fail, #fold, #help, #hint, #quit, #review, #skip, #welcome, #win
Constructor Details
This class inherits a constructor from Drill
Instance Method Details
#reference ⇒ Object
26
27
28
|
# File 'lib/ruby_drills/array/chunk_drill.rb', line 26
def reference
"@names.sort.chunk {|n| n[0]}.map {|char, lines| [char, lines.size]}"
end
|
#setup ⇒ Object
3
4
5
6
7
8
|
# File 'lib/ruby_drills/array/chunk_drill.rb', line 3
def setup
@names = %w[ Al Slartibartfast Aaron Yvonne Bobby ]
@hints = ["Remember, this method is especially useful for sorted series of elements.",
".to_a can be useful to see the output of methods that produce Enumerators",
"http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-chunk"]
end
|
#show ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ruby_drills/array/chunk_drill.rb', line 10
def show
puts %{
@names = #{@names.inspect}
Count the words in @names by the first letter of each name
to produce an array containing:
#{expected}
First sort this array, then use the method that splits self into
multiple Enumerators using the rule given in the block. It
then passes the result of the rule and an Enumerator
of the successive elements to another Enumerable method.
}
end
|
#valid?(input) ⇒ Boolean
30
31
32
|
# File 'lib/ruby_drills/array/chunk_drill.rb', line 30
def valid?(input)
["chunk", "sort"].all? {|fn| input.include?(fn)}
end
|