Sha256: 16ca7c520e576e9a7aecf32d7084aa57b6986102e356b39d65b8683b7746e476

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Carbon
  module Concrete
    module Item
      class Trait
        # An expectation of a trait.  This is a function that an implementing
        # data type must implement to be considered a part of the trait.
        #
        # @api private
        # @note
        #   **This class is frozen upon initialization.**  This means that any
        #   attempt to modify it will result in an error.  In most cases, the
        #   attributes on this class will also be frozen, as well.
        class Expectation
          # The name of the function for this expectation.  This is a string,
          # and can be any valid function name for a carbon function.
          #
          # @return [::String] The function name.
          attr_reader :name

          # The parameters of the function for this expectation.  This is an
          # array of types, which can contain generic parameters.
          #
          # @return [<Type>] The parameter types.
          attr_reader :parameters

          # The return type of the function for this expectation.  This is
          # a single type, which can contain generic parameters.
          #
          # @return [Type] The return type.
          attr_reader :return

          # Initialize the expectation with the given arguments.
          #
          # @see #name
          # @see #parameters
          # @see #return
          # @param name [::String] The name of the function for the expectation.
          # @param parameters [<Type>] The parameters of the function for
          #   the expectation.
          # @param ret [Type] The return type of the function for the
          #   expectation.
          def initialize(name, parameters, ret)
            @name = name
            @parameters = parameters
            @return = ret
            deep_freeze!
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
carbon-core-0.2.1 lib/carbon/concrete/item/trait/expectation.rb
carbon-core-0.2.0 lib/carbon/concrete/item/trait/expectation.rb
carbon-core-0.1.1 lib/carbon/concrete/item/trait/expectation.rb
carbon-core-0.1.0 lib/carbon/concrete/item/trait/expectation.rb