Class: Dry::Types::AnyClass

Inherits:
Nominal
  • Object
show all
Defined in:
lib/dry/types/any.rb

Overview

Any is a nominal type that defines Object as the primitive class

This type is useful in places where you can’t be specific about the type and anything is acceptable.

Constant Summary

Constants inherited from Nominal

Nominal::ALWAYS

Instance Attribute Summary

Attributes inherited from Nominal

#primitive

Attributes included from Options

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Nominal

[], #call_safe, #call_unsafe, #coerce, #constrained?, #default?, #failure, #lax, #optional?, #primitive?, #success, #to_proc, #try, #try_coerce

Methods included from Printable

#to_s

Methods included from Builder

#&, #>, #constrained, #constrained_type, #constructor, #constructor_type, #default, #enum, #fallback, #lax, #maybe, #optional, #|

Methods included from Meta

#meta, #pristine

Methods included from Type

#call, #valid?

Constructor Details

#initialize(**options) ⇒ AnyClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AnyClass.



17
18
19
# File 'lib/dry/types/any.rb', line 17

def initialize(**options)
  super(::Object, **options)
end

Class Method Details

.nameObject



12
13
14
# File 'lib/dry/types/any.rb', line 12

def self.name
  "Any"
end

Instance Method Details

#nameString

Returns:

  • (String)


24
25
26
# File 'lib/dry/types/any.rb', line 24

def name
  "Any"
end

#to_ast(meta: true) ⇒ Array

Returns:



40
41
42
# File 'lib/dry/types/any.rb', line 40

def to_ast(meta: true)
  [:any, meta ? self.meta : EMPTY_HASH]
end

#with(**new_options) ⇒ Type

Parameters:

  • new_options (Hash)

Returns:



33
34
35
# File 'lib/dry/types/any.rb', line 33

def with(**new_options)
  self.class.new(**options, meta: @meta, **new_options)
end