Class: MergeDrill
- Inherits:
-
Drill
show all
- Defined in:
- lib/ruby_drills/hash/merge_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
23
24
25
|
# File 'lib/ruby_drills/hash/merge_drill.rb', line 23
def reference
"@matched_animals.merge(@mismatched_animals) { |key, v1, v2| v1 } "
end
|
#setup ⇒ Object
3
4
5
6
7
|
# File 'lib/ruby_drills/hash/merge_drill.rb', line 3
def setup
@mismatched_animals = {"cat" => "woof", "dog" => "meow", "pig" => "oink" }
@matched_animals = { "cat" => "meow", "dog" => "woof", "frog" => "ribbit"}
@hints = ["http://www.ruby-doc.org/core-2.1.0/Hash.html#method-i-merge"]
end
|
#show ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ruby_drills/hash/merge_drill.rb', line 9
def show
puts %{We have two hashes:
@mismatched_animals: #{@mismatched_animals.inspect}
@matched_animals: #{@matched_animals.inspect}
Create a hash with properly matched key/pair values of animals and sounds:
#{expected.inspect}
Use the Hash method that will return a new hash with non-duplicate keys of
the first and second collectively. If the method uses a block it will
specify how to handle duplicate keys:
}
end
|
#valid?(input) ⇒ Boolean
27
28
29
|
# File 'lib/ruby_drills/hash/merge_drill.rb', line 27
def valid?(input)
input.include?('merge')
end
|