Sha256: 26f029450ed7e7df43f0f13eb4bb350f3366b9728ac988d2a579a79745661cc3

Contents?: true

Size: 715 Bytes

Versions: 3

Compression:

Stored size: 715 Bytes

Contents

#This class behaves like a normal thread - but it shows error-messages and tracebacks. Normal threads dont do that.
class Knj::Thread < Thread
  attr_accessor :data
  
  #Initializes the thread and passes any given arguments to the thread-block.
  def initialize(*args)
    raise "No block was given." unless block_given?
    
    super(*args) do
      begin
        yield(*args)
      rescue SystemExit
        exit
      rescue Exception => e
        print "#{Knj::Errors.error_str(e)}\n\n"
      end
    end
    
    @data = {}
  end
  
  #Returns a key from the data-hash.
  def [](key)
    return @data[key]
  end
  
  #Sets a key on the data-hash.
  def []=(key, value)
    return @data[key] = value
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
knjrbfw-0.0.41 lib/knj/thread.rb
knjrbfw-0.0.40 lib/knj/thread.rb
knjrbfw-0.0.39 lib/knj/thread.rb