Class: Knj::Thread

Inherits:
Thread show all
Defined in:
lib/knj/thread.rb

Overview

This class behaves like a normal thread - but it shows error-messages and tracebacks. Normal threads dont do that.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Thread

Initializes the thread and passes any given arguments to the thread-block.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/knj/thread.rb', line 6

def initialize(*args)
  raise "No block was given." unless block_given?
  
  super(*args) do
    begin
      yield(*args)
    rescue SystemExit, Interrupt
      raise
    rescue Exception => e
      print "#{Knj::Errors.error_str(e)}\n\n"
    end
  end
  
  @data = {}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/knj/thread.rb', line 3

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object

Returns a key from the data-hash.



23
24
25
# File 'lib/knj/thread.rb', line 23

def [](key)
  return @data[key]
end

#[]=(key, value) ⇒ Object

Sets a key on the data-hash.



28
29
30
# File 'lib/knj/thread.rb', line 28

def []=(key, value)
  return @data[key] = value
end