class I8::Set
Public Class Methods
empty()
click to toggle source
Override to build our empty set through {.alloc} so that we can return it in {.new}.
@return [I8::Set]
# File lib/nrser/labs/i8.rb, line 82 def self.empty @empty ||= alloc Hamster::Trie.new( 0 ) end
new(items = [])
click to toggle source
Get a {I8::Set} containing `items`.
Overridden to…
-
Return `items` if items is already a {I8::Set}… sort of like a copy constructor that doesn't actually copy because the instances are immutable.
-
Return an instance of `self` pointing to `items`'s {Hamster::Trie} if `items` is a {Hamster::Set}; this way you get an instance of the correct class but don't do any additional instantiation.
-
Returns {.empty} if `items` responds to `#empty?` truthfully.
Otherwise, defers to `super`.
@param [#each] items
Items for the new set to contain.
@return [I8::Set]
Calls superclass method
# File lib/nrser/labs/i8.rb, line 62 def self.new items = [] case items when self items when Hamster::Set alloc items.instance_variable_get( :@trie ) else if items.respond_to?( :empty? ) && items.empty? self.empty else super items end end end