Class: SortedSet
- Inherits:
-
Set
- Object
- Set
- SortedSet
- Defined in:
- lib/sorted_set.rb
Overview
SortedSet implements a Set whose elements are sorted in ascending
order (according to the return values of their <=> methods) when
iterating over them.
Every element in SortedSet must be mutually comparable to every
other: comparison with <=> must not return nil for any pair of
elements. Otherwise ArgumentError will be raised.
Example
require "sorted_set"
set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
ary = []
set.each do |obj|
ary << obj
end
p ary # => [1, 2, 3, 4, 5, 6]
set2 = SortedSet.new([1, 2, "3"])
set2.each { |obj| } # => raises ArgumentError: comparison of Fixnum with String failed
Instance Method Summary collapse
-
#initialize(*args) ⇒ SortedSet
constructor
Creates a SortedSet.
Constructor Details
#initialize(*args) ⇒ SortedSet
Creates a SortedSet. See Set.new for details.
53 54 55 56 |
# File 'lib/sorted_set.rb', line 53 def initialize(*args) @hash = RBTree.new super end |