Module: Mixture::Types::Access

Included in:
Class, Collection, Hash
Defined in:
lib/mixture/types/access.rb

Overview

Used by certain types to create subtypes of those types. This is useful in collections and hashes, wherein the collection members and hash keys/values all have types as well (and need to be coerced to them).

Instance Method Summary collapse

Instance Method Details

#[](*subs) ⇒ Class

Creates a subtype with the given member types. Any number of subtypes may be used. If a class hasn't been created with the subtypes, it creates a new one.

Parameters:

  • subs (Object)

    The subtypes to use.

Returns:

  • (Class)

    The new subtype.

See Also:

  • #create

17
18
19
20
21
22
# File 'lib/mixture/types/access.rb', line 17

def [](*subs)
  inferred = infer_subs(subs)
  options[:types].fetch([self, inferred]) do
    create(inferred)
  end
end