Class: AllNamesDrill

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



22
23
24
# File 'lib/ruby_drills/array/all_names_drill.rb', line 22

def reference
  "@names.all? {|n| n.size > 4}"
end

#setupObject



3
4
5
6
7
# File 'lib/ruby_drills/array/all_names_drill.rb', line 3

def setup
  @names = %w[ Al Slartibartfast Aaron Yvonne Bobby ]
  @hints = ["Your answer will look something like @names.xxxxx {|y| y.zzz > 4 }",
            "http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-all-3F"]
end

#showObject



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

def show
  puts %{
@names = #{@names.inspect}

Is each name longer than four characters?

Use the method that passes each element of the collection
to the given block and returns true if the block never
returns false or nil.

}
end

#valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby_drills/array/all_names_drill.rb', line 26

def valid?(input)
  input.include?("all?") && (input.include?('size > 4') || input.include?('length > 4'))
end