Class: T::Types::TypedSet

Inherits:
TypedEnumerable show all
Defined in:
lib/types/types/typed_set.rb

Direct Known Subclasses

Untyped

Defined Under Namespace

Classes: Untyped

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TypedEnumerable

#describe_obj, #initialize

Methods inherited from Base

#==, #describe_obj, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #subtype_of?, #to_s, #validate!

Constructor Details

This class inherits a constructor from T::Types::TypedEnumerable

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/types/types/typed_set.rb', line 6

def type
  @type
end

Instance Method Details

#nameObject

overrides Base



13
14
15
# File 'lib/types/types/typed_set.rb', line 13

def name
  "T::Set[#{@type.name}]"
end

#new(*args) ⇒ Object



33
34
35
36
37
38
# File 'lib/types/types/typed_set.rb', line 33

def new(*args)
  # Fine for this to blow up, because hopefully if they're trying to make a
  # Set, they don't mind putting (or already have put) a `require 'set'` in
  # their program directly.
  Set.new(*T.unsafe(args))
end

#recursively_valid?(obj) ⇒ Boolean

overrides Base

Returns:



18
19
20
21
22
23
# File 'lib/types/types/typed_set.rb', line 18

def recursively_valid?(obj)
  # Re-implements non_forcing_is_a?
  return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
  return false unless Object.const_defined?(:Set) # Set is not loaded yet
  obj.is_a?(Set) && super
end

#underlying_classObject



8
9
10
# File 'lib/types/types/typed_set.rb', line 8

def underlying_class
  Hash
end

#valid?(obj) ⇒ Boolean

overrides Base

Returns:



26
27
28
29
30
31
# File 'lib/types/types/typed_set.rb', line 26

def valid?(obj)
  # Re-implements non_forcing_is_a?
  return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
  return false unless Object.const_defined?(:Set) # Set is not loaded yet
  obj.is_a?(Set)
end