class SortedSet


set2.each { |obj| } # => raises ArgumentError: comparison of Fixnum with String failed
set2 = SortedSet.new([1, 2, “3”])
p ary # => [1, 2, 3, 4, 5, 6]
end
ary << obj
set.each do |obj|
ary = []
set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
require “set”
== Example
iterating over the SortedSet.
and el2, else an ArgumentError will be raised when
el2</tt> must not return nil for any elements el1
Also, all elements must be mutually comparable: <tt>el1 <=>
method for comparison.
All elements that are added to a SortedSet must respond to the <=>
#<=> methods) when iterating over them.
yielded in sorted order (according to the return values of their
SortedSet implements a Set that guarantees that it’s element are

def [](*ary) # :nodoc:

:nodoc:
def [](*ary)	# :nodoc:
  new(ary)
end

def initialize(*args, &block) # :nodoc:

:nodoc:
def initialize(*args, &block)	# :nodoc:
  SortedSet.setup
  initialize(*args, &block)
end

def setup # :nodoc:

:nodoc:
def setup	# :nodoc:
  @@setup and return
  module_eval {
    # a hack to shut up warning
    alias old_init initialize
    remove_method :old_init
  }
  begin
uire 'rbtree'
ule_eval %{
ef initialize(*args, &block)
 @hash = RBTree.new
 super
nd
ef add(o)
 o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
 super
nd
lias << add
  rescue LoadError
ule_eval %{
ef initialize(*args, &block)
 @keys = nil
 super
nd
ef clear
 @keys = nil
 super
nd
ef replace(enum)
 @keys = nil
 super
nd
ef add(o)
 o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
 @keys = nil
 super
nd
lias << add
ef delete(o)
 @keys = nil
 @hash.delete(o)
 self
nd
ef delete_if
        block_given? or return enum_for(__method__)
 n = @hash.size
 super
 @keys = nil if @hash.size != n
 self
nd
ef keep_if
 block_given? or return enum_for(__method__)
 n = @hash.size
 super
 @keys = nil if @hash.size != n
 self
nd
ef merge(enum)
 @keys = nil
 super
nd
ef each
 block_given? or return enum_for(__method__)
 to_a.each { |o| yield(o) }
 self
nd
ef to_a
 (@keys = @hash.keys).sort! unless @keys
 @keys
nd
  end
  @@setup = true
end