Class: TypedSet
- Inherits:
-
Set
- Object
- Set
- TypedSet
- 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
-
#klass ⇒ Object
(also: #set_class)
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #add(o) ⇒ Object (also: #<<)
-
#initialize(klass, *args) ⇒ TypedSet
constructor
A new instance of TypedSet.
Constructor Details
#initialize(klass, *args) ⇒ TypedSet
Returns a new instance of TypedSet.
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
#klass ⇒ Object (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: <<
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 |