Sha256: 2d33ca50b44fad3c807b6d7555c9fa99b0f77e7e37251ee064d937ebd279031d

Contents?: true

Size: 1.49 KB

Versions: 22

Compression:

Stored size: 1.49 KB

Contents

=begin rdoc
  Kernel overloads
=end

module Kernel
  def get_latest_caller
    returning Array.new do |arr|
      callstack.size.times {|i| arr << callstack[i][0] unless callstack[i][0] =~ /lib\/poolparty/ }
    end.first
  end
  def callstack( level = 1 )
    call_str_array = caller(level)
    stack = []
    call_str_array.each{ |call_str|
      file, lineno, method = call_str.split(':')
      if method =~ /in `(.*)'/ then
        method = $1.intern()
      end
      stack << [file, lineno.to_i, method]
    }
    stack
  end
  # Nice wait instead of sleep
  def wait(time=5)
    sleep time.is_a?(String) ? eval(time) : time
  end
  def as(klass_or_obj, &block)
    block.in_context(klass_or_obj).call
  end
  def with_warnings_suppressed
    saved_verbosity = $-v
    $-v = nil
    yield
  ensure
    $-v = saved_verbosity
  end
  
  def capture_stdout(&block)
     old_stdout = $stdout
     out = StringIO.new
     $stdout = out
     begin
        block.call if block
     ensure
        $stdout = old_stdout
     end
     out.string
  end

  #redirect stdout and stderr to /dev/null and reopen after block
  def hide_output
    begin
      old_stdout = STDOUT.dup
      old_stderr = STDERR.dup
      STDOUT.reopen(File.open((PLATFORM =~ /mswin/ ? "NUL" : "/dev/null"), 'w'))
      STDERR.reopen(File.open((PLATFORM =~ /mswin/ ? "NUL" : "/dev/null"), 'w'))
      yield if block_given?
    ensure
      STDOUT.flush
      STDOUT.reopen(old_stdout)
      STDERR.flush
      STDERR.reopen(old_stderr)
    end
  end

end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
auser-poolparty-1.1.1 lib/poolparty/core/kernel.rb
auser-poolparty-1.1.3 lib/poolparty/core/kernel.rb
auser-poolparty-1.1.4 lib/poolparty/core/kernel.rb
auser-poolparty-1.1.5 lib/poolparty/core/kernel.rb
auser-poolparty-1.1.6 lib/poolparty/core/kernel.rb
auser-poolparty-1.1.7 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.0 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.1 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.10 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.11 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.12 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.2 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.3 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.4 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.7 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.8 lib/poolparty/core/kernel.rb
auser-poolparty-1.2.9 lib/poolparty/core/kernel.rb
fairchild-poolparty-1.1.3 lib/poolparty/core/kernel.rb
fairchild-poolparty-1.1.4 lib/poolparty/core/kernel.rb
fairchild-poolparty-1.1.5 lib/poolparty/core/kernel.rb