Ruby里的structure和set
# Create a structure with a name in StructStruct.new("Customer", :name, :address) #=> Struct::CustomerStruct::Customer.new("Dave", "123 Main") #=> #<struct Struct::Customer name="Dave", address="123 Main"># Create a structure named by its constantCustomer = Struct.new(:name, :address) #=> CustomerCustomer.new("Dave", "123 Main") #=> #<struct Customer name="Dave", address="123 Main">
#Array hybrid Hashrequire 'set's1 = Set.new [1, 2] # -> #<Set: {1, 2}>s2 = [1, 2].to_set # -> #<Set: {1, 2}>s1 == s2 # -> trues1.add("foo") # -> #<Set: {1, 2, "foo"}>s1.merge([2, 6]) # -> #<Set: {6, 1, 2, "foo"}>s1.subset? s2 # -> falses2.subset? s1 # -> true