Class: ROC::Set
Instance Attribute Summary
Attributes inherited from Base
#key, #options
Instance Method Summary
collapse
-
#<<(obj) ⇒ Object
-
#clobber(vals) ⇒ Object
implementing ArrayType ##.
-
#delete(val) ⇒ Object
implement (if posible) destructive methods that would otherwise raise.
-
#pop(*args) ⇒ Object
-
#push(*objs) ⇒ Object
-
#sdiff(*other_sets) ⇒ Object
(also: #diff, #-)
-
#sdiffstore(*other_sets) ⇒ Object
(also: #diffstore, #diff_store, #set_as_diff_of)
-
#sinter(*other_sets) ⇒ Object
(also: #inter, #intersect, #&)
-
#sinterstore(*other_sets) ⇒ Object
(also: #interstore, #inter_store, #set_as_intersect_of)
-
#smove(other_set, val) ⇒ Object
(also: #move, #move_into)
-
#sunion(*other_sets) ⇒ Object
(also: #union, #|)
-
#sunionstore(*other_sets) ⇒ Object
(also: #unionstore, #union_store, #set_as_union_of)
-
#to_hash ⇒ Object
(also: #to_h)
deserializing_method, nonserializing_method, serializing_and_deserializing_method, serializing_method, zero_arg_method
#sort, #sort!
#clear, #delete_at, #delete_if, #fill, included, #insert, #inspect, #keep_if, #replace, #shift, #to_a, #to_array, #to_ary, #unshift, #values=
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
#<<(obj) ⇒ Object
115
116
117
|
# File 'lib/roc/objects/set.rb', line 115
def <<(obj)
self.push(obj)
end
|
#clobber(vals) ⇒ Object
implementing ArrayType ##
135
136
137
138
139
140
|
# File 'lib/roc/objects/set.rb', line 135
def clobber(vals)
self.storage.multi do
self.forget
vals.each{|v| self << v}
end
end
|
#delete(val) ⇒ Object
implement (if posible) destructive methods that would otherwise raise
94
95
96
97
98
99
100
|
# File 'lib/roc/objects/set.rb', line 94
def delete(val)
if self.srem(val)
val
else
nil
end
end
|
#pop(*args) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/roc/objects/set.rb', line 119
def pop(*args)
if 0 == args.size
self.spop
elsif 1 == args.size
(self.storage.multi do
args[0].times do
self.spop
end
end).reverse
else
raise ArgumentError, "wrong number of arguments (#{args.size} for 1)"
end
end
|
#push(*objs) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/roc/objects/set.rb', line 102
def push(*objs)
if 1 == objs.size
self.sadd(objs[0])
elsif objs.size > 1
self.storage.multi do
objs.each do |obj|
self.sadd(obj)
end
end
end
self
end
|
#sdiff(*other_sets) ⇒ Object
Also known as:
diff, -
54
55
56
|
# File 'lib/roc/objects/set.rb', line 54
def sdiff(*other_sets)
self.call :sdiff, *other_sets.map{|s| s.key}
end
|
#sdiffstore(*other_sets) ⇒ Object
Also known as:
diffstore, diff_store, set_as_diff_of
74
75
76
|
# File 'lib/roc/objects/set.rb', line 74
def sdiffstore(*other_sets)
self.call :sdiffstore, *other_sets.map{|s| s.key}
end
|
#sinter(*other_sets) ⇒ Object
Also known as:
inter, intersect, &
41
42
43
|
# File 'lib/roc/objects/set.rb', line 41
def sinter(*other_sets)
self.call :sinter, *other_sets.map{|s| s.key}
end
|
#sinterstore(*other_sets) ⇒ Object
Also known as:
interstore, inter_store, set_as_intersect_of
60
61
62
|
# File 'lib/roc/objects/set.rb', line 60
def sinterstore(*other_sets)
self.call :sinterstore, *other_sets.map{|s| s.key}
end
|
#smove(other_set, val) ⇒ Object
Also known as:
move, move_into
35
36
37
|
# File 'lib/roc/objects/set.rb', line 35
def smove(other_set, val)
self.call :smove, other_set.key, val
end
|
#sunion(*other_sets) ⇒ Object
Also known as:
union, |
48
49
50
|
# File 'lib/roc/objects/set.rb', line 48
def sunion(*other_sets)
self.call :sunion, *other_sets.map{|s| s.key}
end
|
#sunionstore(*other_sets) ⇒ Object
Also known as:
unionstore, union_store, set_as_union_of
67
68
69
|
# File 'lib/roc/objects/set.rb', line 67
def sunionstore(*other_sets)
self.call :sunionstore, *other_sets.map{|s| s.key}
end
|
#to_hash ⇒ Object
Also known as:
to_h
83
84
85
86
87
88
89
|
# File 'lib/roc/objects/set.rb', line 83
def to_hash
hsh = {}
self.smembers.each do |val|
hsh[val] = true
end
hsh
end
|