Class: Yadriggy::TypeChecker::TypeDef

Inherits:
Object
  • Object
show all
Defined in:
lib/yadriggy/typecheck.rb

Overview

Type definition. It expresses a class (or singular class) definition. It maps an instance variable name or a method name to its type.

Instance Method Summary collapse

Constructor Details

#initializeTypeDef

Returns a new instance of TypeDef.



131
132
133
# File 'lib/yadriggy/typecheck.rb', line 131

def initialize()
  @names = {}
end

Instance Method Details

#[](name) ⇒ Type|nil

Gets the type of an instance variable or a method.

Parameters:

  • name (String|Symbol)

    its name. ‘name` can be any object with `to_sym`.

Returns:

  • (Type|nil)

    its type.



139
140
141
# File 'lib/yadriggy/typecheck.rb', line 139

def [](name)
  @names[name.to_sym]
end

#[]=(name, type) ⇒ Type

Adds an instance variable or a method.

Parameters:

  • name (String|Symbol)

    its name. ‘name` can be any object with `to_sym`.

  • type (Type)

    its type.

Returns:

  • (Type)

    the added type.



148
149
150
# File 'lib/yadriggy/typecheck.rb', line 148

def []=(name, type)
  @names[name.to_sym] = type
end