Class: TakeWhileDrill

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



18
19
20
# File 'lib/ruby_drills/array/take_while_drill.rb', line 18

def reference
  "@a.take_while {|x| x < 4}"
end

#setupObject



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

def setup
  @a = [1, 2, 3, 4, 5, 0]
  @hints = ["http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-take_while"]
end

#showObject



8
9
10
11
12
13
14
15
16
# File 'lib/ruby_drills/array/take_while_drill.rb', line 8

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

Use the Enumerable method that passes elements to a block
until the block returns nil or false, then stops iterating and
returns an array of all prior elements to return #{expected.inspect}:
}
end

#valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


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

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