Class: RejectDrill

Inherits:
Drill
  • Object
show all
Defined in:
lib/ruby_drills/hash/reject_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

#referenceObject



21
22
23
# File 'lib/ruby_drills/hash/reject_drill.rb', line 21

def reference
  "@dog_breeds.reject {|dog, size| size == 'large' }"
end

#setupObject



3
4
5
6
7
# File 'lib/ruby_drills/hash/reject_drill.rb', line 3

def setup
  @dog_breeds = { "black lab" => "medium", "chihuahua" => "small", "pitbull" => "medium",
                  "poodle" => "small", "great dane" => "large"}
  @hints = ["http://www.ruby-doc.org/core-2.1.0/Hash.html#method-i-reject"]
end

#showObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_drills/hash/reject_drill.rb', line 9

def show
  puts %{
We have a hash:
@dog_breeds: #{@dog_breeds.inspect}

Filter this hash to return only small and medium dog breeds:
#{expected.inspect}

Use the Hash method that "returns a new hash consisting of entries for which the block returns false":
}
end

#valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ruby_drills/hash/reject_drill.rb', line 25

def valid?(input)
  input.include?('reject')
end