class Restruct::Hash
Public Instance Methods
[](key)
click to toggle source
# File lib/restruct/hash.rb, line 9 def [](key) deserialize connection.call('HGET', id, key) end
clear()
click to toggle source
# File lib/restruct/hash.rb, line 56 def clear destroy self end
delete(key)
click to toggle source
# File lib/restruct/hash.rb, line 39 def delete(key) value = self[key] connection.lazy 'HDEL', id, key value end
delete_if() { |k, v| ... }
click to toggle source
# File lib/restruct/hash.rb, line 45 def delete_if each { |k,v| delete k if yield k, v } self end
each() { |key, self| ... }
click to toggle source
# File lib/restruct/hash.rb, line 93 def each keys.each { |key| yield key, self[key] } end
Also aliased as: each_pair
each_key() { |k| ... }
click to toggle source
# File lib/restruct/hash.rb, line 98 def each_key each { |k,v| yield k } end
each_value() { |v| ... }
click to toggle source
# File lib/restruct/hash.rb, line 102 def each_value each { |k,v| yield v } end
empty?()
click to toggle source
# File lib/restruct/hash.rb, line 89 def empty? size == 0 end
fetch(key, default=nil, &block)
click to toggle source
# File lib/restruct/hash.rb, line 13 def fetch(key, default=nil, &block) if key? key self[key] else raise KeyError, "key not found: #{key}" if default.nil? && block.nil? default || block.call(key) end end
keep_if() { |k, v| ... }
click to toggle source
# File lib/restruct/hash.rb, line 50 def keep_if each { |k,v| delete k unless yield k, v } self end
Also aliased as: select!
key(value)
click to toggle source
# File lib/restruct/hash.rb, line 22 def key(value) index = values.index value keys[index] if index end
key?(key)
click to toggle source
# File lib/restruct/hash.rb, line 73 def key?(key) connection.call('HEXISTS', id, key) == 1 end
Also aliased as: has_key?
keys()
click to toggle source
# File lib/restruct/hash.rb, line 61 def keys connection.call 'HKEYS', id end
size()
click to toggle source
# File lib/restruct/hash.rb, line 83 def size connection.call 'HLEN', id end
store(key, value)
click to toggle source
# File lib/restruct/hash.rb, line 27 def store(key, value) connection.lazy 'HSET', id, key, serialize(value) value end
Also aliased as: []=
to_h()
click to toggle source
# File lib/restruct/hash.rb, line 106 def to_h connection.call('HGETALL', id).each_slice(2).each_with_object({}) do |(k,v), hash| hash[k] = deserialize v end end
Also aliased as: to_primitive
update(hash)
click to toggle source
# File lib/restruct/hash.rb, line 33 def update(hash) hash.each { |k,v| store k, v } self end
Also aliased as: merge!
value?(value)
click to toggle source
# File lib/restruct/hash.rb, line 78 def value?(value) values.include? value end
Also aliased as: has_value?
values()
click to toggle source
# File lib/restruct/hash.rb, line 65 def values connection.call('HVALS', id).map { |v| deserialize v } end
values_at(*keys)
click to toggle source
# File lib/restruct/hash.rb, line 69 def values_at(*keys) keys.map { |k| self[k] } end
Private Instance Methods
deserialize(string)
click to toggle source
# File lib/restruct/hash.rb, line 119 def deserialize(string) string end
serialize(string)
click to toggle source
# File lib/restruct/hash.rb, line 115 def serialize(string) string end