Class: Rtype::Behavior::TypedSet

Inherits:
Base show all
Defined in:
lib/rtype/behavior/typed_set.rb

Overview

Typed set behavior. empty set allowed

Instance Method Summary collapse

Methods inherited from Base

[]

Constructor Details

#initialize(type) ⇒ TypedSet

Returns a new instance of TypedSet.



5
6
7
8
# File 'lib/rtype/behavior/typed_set.rb', line 5

def initialize(type)
  @type = type
  Rtype.assert_valid_argument_type_sig_element(@type)
end

Instance Method Details

#error_message(value) ⇒ Object



21
22
23
# File 'lib/rtype/behavior/typed_set.rb', line 21

def error_message(value)
  "Expected #{value.inspect} to be a set with type #{@type.inspect}"
end

#valid?(value) ⇒ Boolean

Returns:



10
11
12
13
14
15
16
17
18
19
# File 'lib/rtype/behavior/typed_set.rb', line 10

def valid?(value)
  if value.is_a?(Set)
    any = value.any? do |e|
      !Rtype::valid?(@type, e)
    end
    !any
  else
    false
  end
end