--- tags: minimeet, Ruby --- # Set > https://ruby-doc.org/stdlib-3.1.2/libdoc/set/rdoc/Set.html array 與 hash 的混血兒 ```ruby Set[1] Set.new [1] [1].to_set Set[1].to_a Set.new([1]) { |n| n * 10 } ``` 使用方式跟 array 幾乎一模一樣 但是無序 查找的方式跟 hash 一樣 ```ruby { a: 1 }.first Set[1].first ``` # comparision ```ruby [1] == [1] Set[1] == Set[1] ``` # both / exclude ```ruby [1, 2, 3] & [3, 4, 5] Set[1, 2, 3] & [3, 4, 5] Set[1, 2, 3] ^ [3, 4, 5] ``` # + / | / << / add ```ruby [1] + [1] Set[1] + [1] Set[1] | [1] Set[1] << 1 Set[1].add 1 Set[1].add? 2 Set[1].add? 1 ``` # - ```ruby Set[1] - [1] ``` # include ```ruby Set[1] === 1 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up