Module: KKernel

Included in
Object
Defined in
lib/kyanite/general/kernel.rb

Object Additions

Kyanite definitions

Object, KKernel

Kyanite tests and examples

TestKyaniteObject

Usage

require 'kyanite/basics'

Instance Method Summary (collapse)

Instance Method Details

- (Object) repeat_n_seconds(n = 1, &block)

Repeats a block until the time is up. Returns the number of passes. All Exceptions are caught (=> bad blocks seem to run faster). Example (using Numeric):

3.seconds do
 puts Time.now.inspect
end

Example (using KKernel):

repeat_n_seconds 3 do
 puts Time.now.inspect
end


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kyanite/general/kernel.rb', line 27

def repeat_n_seconds( n=1, &block )
  timer = Timer.new(n) 
  begin
    timer.start
      count = 0
      until false
        count += 1
        yield block if block
      end
    timer.stop
  rescue TimeoutError 
    return count      
  rescue 
    return count  
  rescue 
    return count             
  end # begin 
end

- (Object) silence_warnings

Silence all Ruby warnings for the following block. Useful to override constants. Example:

TEST = 1
silence_warnings do
 TEST = 2
end


58
59
60
61
62
63
# File 'lib/kyanite/general/kernel.rb', line 58

def silence_warnings
     old_verbose, $VERBOSE = $VERBOSE, nil
     yield
  ensure
     $VERBOSE = old_verbose
end