Class: GroupByDrill
- Inherits:
-
Drill
- Object
- Drill
- GroupByDrill
show all
- Defined in:
- lib/ruby_drills/hash/group_by_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
20
21
22
|
# File 'lib/ruby_drills/hash/group_by_drill.rb', line 20
def reference
"@mario_bros.group_by { |character, personality| personality } "
end
|
#setup ⇒ Object
3
4
5
6
|
# File 'lib/ruby_drills/hash/group_by_drill.rb', line 3
def setup
@mario_bros = { "Mario"=>"good", "Luigi"=>"good", "Bowser"=>"evil", "Peach"=>"good", "Toad"=>"good", "Yoshi" => "superb" }
@hints = ["http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-group_by"]
end
|
#show ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/ruby_drills/hash/group_by_drill.rb', line 8
def show
puts %{We have one hash:
@mario_bros: #{@mario_bros.inspect}
Organize the Mario Bros by their personality:
#{expected.inspect}
Use the Enumerable method that will return a hash of key/value pairs where the keys values and the
values are an array of key/value pairs.
}
end
|
#valid?(input) ⇒ Boolean
24
25
26
|
# File 'lib/ruby_drills/hash/group_by_drill.rb', line 24
def valid?(input)
input.include?('group_by')
end
|