How to Build an Interval Timer Method in Ruby

0
3282

This coding exercise tests your ability to create an interval timer method in Ruby that runs a process at any interval passed to the method. Additionally, the method needs to be able to take a block.

Summary

Build out an interval method that repeatedly runs a process.

Exercise File

Code File

Exercise Description

This coding exercise tests your ability to create an interval timer method in Ruby that runs a process at any interval passed to the method. Additionally, the method needs to be able to take a block.

Example Process

interval 2 do
  puts "hey there"
end

# waits 2 seconds then prints "hey there"
# waits 2 seconds then prints "hey there"
# waits 2 seconds then prints "hey there"
# waits 2 seconds then prints "hey there"
# ...

Real World Usage

You will practice two key coding practices with this exercise:

  • Building methods that can yield to blocks, this is an important process when building complex methods.
  • Utilizing Ruby’s sleep method to manage the execution of a process.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here