Module: KKernel
- Included in
- Object
- Defined in
- lib/kyanite/general/kernel.rb
Object Additions
- Kyanite tests and examples
- Usage
-
require 'kyanite/basics'
Instance Method Summary (collapse)
-
- (Object) repeat_n_seconds(n = 1, &block)
Repeats a block until the time is up.
-
- (Object) silence_warnings
Silence all Ruby warnings for the following block.
Instance Method Details
- (Object) repeat_n_seconds(n = 1, &block)
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 |