Class: NeoScout::ConstrainedSet
- Inherits:
-
Set
- Object
- Set
- NeoScout::ConstrainedSet
- Defined in:
- lib/neoscout/tools.rb
Instance Method Summary collapse
- #<<(elem) ⇒ Object
-
#initialize(*args, &elem_test) ⇒ ConstrainedSet
constructor
A new instance of ConstrainedSet.
- #valid_elem?(elem) ⇒ Boolean
Constructor Details
#initialize(*args, &elem_test) ⇒ ConstrainedSet
Returns a new instance of ConstrainedSet.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/neoscout/tools.rb', line 51 def initialize(*args, &elem_test) @elem_test = elem_test case when args.length == 0 super when args.length == 1 args = args[0] raise ArgumentError unless (args.all? &@elem_test) super args else raise ArgumentError end end |
Instance Method Details
#<<(elem) ⇒ Object
69 70 71 72 |
# File 'lib/neoscout/tools.rb', line 69 def <<(elem) raise ArgumentError unless valid_elem?(elem) super elem end |
#valid_elem?(elem) ⇒ Boolean
65 66 67 |
# File 'lib/neoscout/tools.rb', line 65 def valid_elem?(elem) @elem_test.call(elem) end |