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.



134
135
136
# File 'lib/yadriggy/typecheck.rb', line 134

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.



142
143
144
# File 'lib/yadriggy/typecheck.rb', line 142

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.



151
152
153
# File 'lib/yadriggy/typecheck.rb', line 151

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