Class: Ikra::Symbolic::ArrayCommand::ClassMethods::WeakCache

Inherits:
Object
  • Object
show all
Defined in:
lib/types/types/array_command_type.rb

Overview

TODO: Check what was wrong with the subclassed Hash…

Instance Method Summary collapse

Constructor Details

#initializeWeakCache

Returns a new instance of WeakCache.



15
16
17
# File 'lib/types/types/array_command_type.rb', line 15

def initialize
    @values = []
end

Instance Method Details

#add_value(value) ⇒ Object



33
34
35
# File 'lib/types/types/array_command_type.rb', line 33

def add_value(value)
    @values.push(WeakRef.new(value))
end

#get_value(value) ⇒ Object

Raises:

  • (RuntimeError)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/types/types/array_command_type.rb', line 19

def get_value(value)
    @values.delete_if do |obj|
        begin
            if obj == value
                return obj.__getobj__
            end
        rescue WeakRef::RefError
            true
        end
    end

    raise RuntimeError.new("Value not found")
end

#include?(value) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/types/types/array_command_type.rb', line 37

def include?(value)
    @values.delete_if do |obj|
        begin
            if obj == value
                return true
            end
        rescue WeakRef::RefError
            true
        end
    end

    return false
end