|
1 | 1 | # Set |
2 | 2 |
|
3 | | -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/set`. To experiment with that code, run `bin/console` for an interactive prompt. |
| 3 | +This library provides the Set class, which deals with a collection of |
| 4 | +unordered values with no duplicates. It is a hybrid of Array's |
| 5 | +intuitive inter-operation facilities and Hash's fast lookup. |
4 | 6 |
|
5 | | -TODO: Delete this and the text above, and describe your gem |
| 7 | +The method `to_set` is added to Enumerable for convenience. |
| 8 | + |
| 9 | +Set implements a collection of unordered values with no duplicates. |
| 10 | +This is a hybrid of Array's intuitive inter-operation facilities and |
| 11 | +Hash's fast lookup. |
| 12 | + |
| 13 | +Set is easy to use with Enumerable objects (implementing `each`). |
| 14 | +Most of the initializer methods and binary operators accept generic |
| 15 | +Enumerable objects besides sets and arrays. An Enumerable object can |
| 16 | +be converted to Set using the `to_set` method. |
| 17 | + |
| 18 | +Set uses Hash as storage, so you must note the following points: |
| 19 | + |
| 20 | +* Equality of elements is determined according to Object#eql? and |
| 21 | + Object#hash. Use Set#compare_by_identity to make a set compare its |
| 22 | + elements by their identity. |
| 23 | + |
| 24 | +* Set assumes that the identity of each element does not change while |
| 25 | + it is stored. Modifying an element of a set will render the set to |
| 26 | + an unreliable state. |
| 27 | + |
| 28 | +* When a string is to be stored, a frozen copy of the string is stored |
| 29 | + instead unless the original string is already frozen. |
| 30 | + |
| 31 | +### Comparison |
| 32 | + |
| 33 | +The comparison operators `<`, `>`, `<=`, and `>=` are implemented as |
| 34 | +shorthand for the {proper_,}{subset?,superset?} methods. The `<=>` |
| 35 | +operator reflects this order, or return `nil` for sets that both have |
| 36 | +distinct elements (`{x, y}` vs. `{x, z}` for example). |
6 | 37 |
|
7 | 38 | ## Installation |
8 | 39 |
|
@@ -37,8 +68,6 @@ s2.subset?(s1) #=> true |
37 | 68 |
|
38 | 69 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. |
39 | 70 |
|
40 | | -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
41 | | - |
42 | 71 | ## Contributing |
43 | 72 |
|
44 | 73 | Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/set. |
|
0 commit comments