Class: ROC::Hash
Instance Attribute Summary
Attributes inherited from Base
#key, #options
Instance Method Summary
collapse
deserializing_method, nonserializing_method, serializing_and_deserializing_method, serializing_method, zero_arg_method
Methods inherited from Base
delegate_methods, #initialize, #method_missing, #respond_to?, #seed
#eval
Constructor Details
This class inherits a constructor from ROC::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ROC::Base
Instance Method Details
#clear ⇒ Object
107
108
109
|
# File 'lib/roc/objects/hash.rb', line 107
def clear
self.replace({})
end
|
#clobber(data) ⇒ Object
124
125
126
127
128
129
130
131
|
# File 'lib/roc/objects/hash.rb', line 124
def clobber(data)
self.storage.multi do
self.forget
if data.size > 0
self.merge!(data)
end
end
end
|
#decrby(field, by) ⇒ Object
75
76
77
|
# File 'lib/roc/objects/hash.rb', line 75
def decrby(field, by)
self.hincrby field, -by
end
|
#decrement(field, by = nil) ⇒ Object
83
84
85
|
# File 'lib/roc/objects/hash.rb', line 83
def decrement(field, by=nil)
self.hincrby field, -(by || 1)
end
|
#delete(field) ⇒ Object
96
97
98
99
100
|
# File 'lib/roc/objects/hash.rb', line 96
def delete(field)
val = self.hget(field)
self.hdel(field)
val
end
|
#delete_if ⇒ Object
111
112
113
|
# File 'lib/roc/objects/hash.rb', line 111
def delete_if
raise NotImplementedError
end
|
#empty? ⇒ Boolean
71
72
73
|
# File 'lib/roc/objects/hash.rb', line 71
def empty?
0 == self.hlen
end
|
#has_value?(val) ⇒ Boolean
Also known as:
value?
66
67
68
|
# File 'lib/roc/objects/hash.rb', line 66
def has_value?(val)
self.values.include?(val)
end
|
#hincrby(field, increment) ⇒ Object
Also known as:
incrby
23
24
25
|
# File 'lib/roc/objects/hash.rb', line 23
def hincrby(field, increment)
self.call :hincrby, field, increment
end
|
#hmget(*fields) ⇒ Object
Also known as:
mget, values_at
36
37
38
|
# File 'lib/roc/objects/hash.rb', line 36
def hmget(*fields)
self.call :hmget, *fields
end
|
#hmset(*pairs) ⇒ Object
Also known as:
mset
41
42
43
|
# File 'lib/roc/objects/hash.rb', line 41
def hmset(*pairs)
self.call :hmset, *pairs
end
|
#hset(field, val) ⇒ Object
Also known as:
set, []=, store
46
47
48
|
# File 'lib/roc/objects/hash.rb', line 46
def hset(field, val)
self.call :hset, field, val
end
|
#hsetnx(field, val) ⇒ Object
Also known as:
setnx
53
54
55
|
# File 'lib/roc/objects/hash.rb', line 53
def hsetnx(field, val)
self.call :hsetnx, field, val
end
|
#increment(field, by = nil) ⇒ Object
79
80
81
|
# File 'lib/roc/objects/hash.rb', line 79
def increment(field, by=nil)
self.hincrby field, (by || 1)
end
|
#merge!(hsh) ⇒ Object
Also known as:
update
implement (if posible) destructive methods that would otherwise raise
89
90
91
92
93
|
# File 'lib/roc/objects/hash.rb', line 89
def merge!(hsh)
raise ArgumentError, 'block version not supported' if block_given?
self.hmset(*hsh.to_a.flatten)
self
end
|
#replace(hsh) ⇒ Object
102
103
104
105
|
# File 'lib/roc/objects/hash.rb', line 102
def replace(hsh)
self.clobber(hsh)
self
end
|
#shift ⇒ Object
115
116
117
|
# File 'lib/roc/objects/hash.rb', line 115
def shift
raise NotImplementedError
end
|