made it work, more or less, with ruby 1.9
[nyuron.git] / classes / cache / container.rb
blobabda8eb253aa831e1d3888f20ef2e2464c444d59
1 class CacheClass
2         class Container
3                 def initialize(type)
4                         @type = type
5                         @table = {}
6                 end
8                 ## redirects to either [] or []=
9                 def method_missing(a, val=nil)
10                         key = a.to_s
11                         if key[-1] == ?=
12                                 key.slice!(-1)
13         #                       log "self[#{key}] = #{val}"
14                                 self[key] = val
15                         else
16                                 self[key]
17                         end
18                 end
20                 ## getter for @table, to perform raw operations
21                 def __table__()
22                         @table
23                 end
25                 ## getter
26                 def [](index)
27                         @table[index]
28                 end
30                 ## setter
31                 ##
32                 ## Note: the @table value is not changed here but in Neuron#value=
33                 def []=(x, y)
34                         neuron = Neuron.from_query("type=? AND key=?", @type, x)
35                         if neuron.empty?
36                                 neuron = Query.create_and_return(@type, x, y)
37                         end
38                         neuron.value = y
39                 end
41                 ## API.sync(@type)
42                 def sync!
43                         API.sync(@type)
44                 end
45         end
46 end