Class: Set

Inherits:
Object show all
Defined in:
lib/kyanite/set.rb

Overview

Set Classes and Additions

Kyanite definitions

Set, SortedSet, OrderedSet

Kyanite tests and examples

TestKyaniteSet

Usage

require ‘kyanite/set’

Differences between the set classes

Set

is unordered. Examples: test_set

OrderedSet

is ordered, it retains the original order, but it will not continually re-sorted – as long you don’t use Dictionary#order_by. Examples: test_ordered_set

SortedSet

is ordered and sorted. It is always in order. Examples: test_sorted_set

Direct Known Subclasses

OrderedSet

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Integer

Comparison operator (by size)

Returns:



34
35
36
# File 'lib/kyanite/set.rb', line 34

def <=>(other)
  self.size <=> other.size
end

#firstObject

Returns any element.

Returns:

  • any element



44
45
46
47
48
# File 'lib/kyanite/set.rb', line 44

def first
  @hash.each do |key, value|
    return key
  end  
end

#lastObject

Returns any other element.

Returns:

  • any other element



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kyanite/set.rb', line 52

def last
  first = nil
  @hash.each do |key, value|
    if first.nil?
      first = key
      next
    else
      return key
    end #if
  end #do 
end

#push(elt) ⇒ Object

Adds the element to the set.



27
28
29
# File 'lib/kyanite/set.rb', line 27

def push(elt)
  self << elt
end