Module: TryCatch::Memory

Defined in:
lib/try-catch.rb

Constant Summary collapse

@@memoryspace =
{}

Class Method Summary collapse

Class Method Details

.load(object_id) ⇒ Object

loaded_exs= @@memoryspace return nil if loaded_exs.nil? return loaded_exs.pop unless loaded_exs.class != Array



35
36
37
# File 'lib/try-catch.rb', line 35

def load object_id
  ( @@memoryspace[object_id] || [] ).last
end

.save(object_id, exception) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/try-catch.rb', line 8

def save object_id, exception

  begin

    unless exception.class <= Exception
      raise ArgumentError, "invalid exception attempt to be saved"
    end

    @@memoryspace[object_id] ||= []

    if @@memoryspace[object_id].count >= 100
      @@memoryspace[object_id].shift
    end

    @@memoryspace[object_id].push exception

    return true
  rescue ArgumentError
    return false
  end

end