首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

Ruby里的structure跟set

2012-12-22 
Ruby里的structure和set# Create a structure with a name in StructStruct.new(Customer, :name, :addr

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

热点排行