File: any.rb

package info (click to toggle)
ruby-dry-types 1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 504 kB
  • sloc: ruby: 3,059; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 912 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Dry
  module Types
    # 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.
    #
    # @api public
    class AnyClass < Nominal
      def self.name
        'Any'
      end

      # @api private
      def initialize(**options)
        super(::Object, **options)
      end

      # @return [String]
      #
      # @api public
      def name
        'Any'
      end

      # @param [Hash] new_options
      #
      # @return [Type]
      #
      # @api public
      def with(**new_options)
        self.class.new(**options, meta: @meta, **new_options)
      end

      # @return [Array]
      #
      # @api public
      def to_ast(meta: true)
        [:any, meta ? self.meta : EMPTY_HASH]
      end
    end

    Any = AnyClass.new
  end
end