Class: TypedSet

Inherits:
Set
  • Object
show all
Defined in:
lib/typedset.rb

Overview

based on RestricedSet from Ruby’s stdlib, cf github.com/ruby/ruby/blob/72ef219804e5524848170a197887a95718334e2a/lib/set.rb#L627-717 not sure why it’s been commented out I should follow these things

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, *args) ⇒ TypedSet

Returns a new instance of TypedSet.

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/typedset.rb', line 12

def initialize (klass, *args)
  raise ArgumentError, "require a Class object" unless klass.class == Class
  @klass = klass
  super args
end

Instance Attribute Details

#klassObject (readonly) Also known as: set_class

Returns the value of attribute klass.



9
10
11
# File 'lib/typedset.rb', line 9

def klass
  @klass
end

Instance Method Details

#add(o) ⇒ Object Also known as: <<

Raises:

  • (ArgumentError)


18
19
20
21
# File 'lib/typedset.rb', line 18

def add o
  raise ArgumentError, "members must be of class #{@klass}" unless o.class == @klass
  super o
end