Class: SortableSet
Instance Method Summary collapse
- #add(*items) ⇒ Object
- #dup ⇒ Object
-
#initialize(ary = [], &compare) ⇒ SortableSet
constructor
A new instance of SortableSet.
Methods inherited from Set
#==, #each, #include?, #inspect, #size, #to_a
Constructor Details
#initialize(ary = [], &compare) ⇒ SortableSet
Returns a new instance of SortableSet.
51 52 53 54 |
# File 'lib/include/set.rb', line 51 def initialize(ary = [], &compare) @set = ary.uniq.sort(&compare) @compare = compare end |
Instance Method Details
#add(*items) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/include/set.rb', line 56 def add(*items) items.each do |i| j = Bisect.bisect_left(@set, i, &@compare) @set.insert(j, i) unless @set[j] == i end return self end |
#dup ⇒ Object
64 65 66 |
# File 'lib/include/set.rb', line 64 def dup self.class.new(@set.dup, &@compare) end |