class Carbon::Concrete::Item::Trait
A trait. This says that a specific type behaves with a certain set of functions.
@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.
Attributes
expectations[R]
The expectations for the trait.
@api semipublic @example
trait.expectations # => [#<Carbon::Concrete::Item::Trait::Expectation +)]
@return [Set<Expectation>]
Public Class Methods
from(type)
click to toggle source
(see Item::Base.from
)
# File lib/carbon/concrete/item/trait.rb, line 21 def self.from(type) { type: type, expectations: [] } end
new(data)
click to toggle source
Initialize the trait with data.
@param data [::Hash] The data to initialize the trait with. @option data [Type] :type The name of the trait type. @option data [<(::String, <Type>, Type
)>] :expectations
The expectations that the trait requires.
# File lib/carbon/concrete/item/trait.rb, line 40 def initialize(data) @type = data.fetch(:type) @generics = @type.generics @name = @type.to_s derive_expectations(data.fetch(:expectations)) derive_dependencies deep_freeze! end
Public Instance Methods
call(_build, _generics)
click to toggle source
(see Base#call
)
# File lib/carbon/concrete/item/trait.rb, line 51 def call(_build, _generics) # do nothing. end
Private Instance Methods
derive_dependencies()
click to toggle source
# File lib/carbon/concrete/item/trait.rb, line 62 def derive_dependencies @expectations.each do |expect| @dependencies.merge(expect.parameters) @dependencies << expect.return end end
derive_expectations(expectations)
click to toggle source
# File lib/carbon/concrete/item/trait.rb, line 57 def derive_expectations(expectations) expects = expectations.map { |e| Expectation.new(*e) } @expectations = Set.new(expects) end