Created
January 17, 2010 23:39
-
-
Save anonymous/279658 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
class Set | |
def initialize(*elems) | |
@redis = Redis.new | |
elems.each do |elem| | |
@redis.set_add(object_id, elem) | |
end | |
end | |
def members | |
@redis.set_members(object_id) | |
end | |
def union(other) | |
ret = Set.new | |
@redis.set_union_store(ret.object_id, object_id, other.object_id) | |
ret | |
end | |
end | |
a = Set.new(1,2) | |
b = Set.new(3,4) | |
puts a.union(b).members #1,2,3,4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment