Module: Types

Defined in:
lib/types/any.rb,
lib/types.rb,
lib/types/nil.rb,
lib/types/hash.rb,
lib/types/array.rb,
lib/types/block.rb,
lib/types/class.rb,
lib/types/float.rb,
lib/types/tuple.rb,
lib/types/lambda.rb,
lib/types/method.rb,
lib/types/string.rb,
lib/types/symbol.rb,
lib/types/boolean.rb,
lib/types/decimal.rb,
lib/types/generic.rb,
lib/types/integer.rb,
lib/types/numeric.rb,
lib/types/version.rb

Overview

Copyright, 2020, by Samuel G. D. Williams. <www.codeotaku.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: Boolean, Decimal, Float, Generic, Integer, Nil, Numeric, String, Symbol Classes: Any, Array, Block, Class, Hash, Lambda, Method, Tuple

Constant Summary collapse

VALID_SIGNATURE =
/\A[a-zA-Z\(\):, |]+\z/
VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.Any(*types) ⇒ Object

A type constructor.

“‘ruby Any(Integer, String) “`

See [Any.initialize](#Bake::Types::Any::initialize).



84
85
86
# File 'lib/types/any.rb', line 84

def self.Any(*types)
	Any.new(types)
end

.Array(item_type = Any) ⇒ Object



67
68
69
# File 'lib/types/array.rb', line 67

def self.Array(item_type = Any)
	Array.new(item_type)
end

.Block(*argument_types, returns: nil) ⇒ Object



50
51
52
# File 'lib/types/block.rb', line 50

def self.Block(*argument_types, returns: nil)
	Block.new(argument_types, returns)
end

.Class(base = Object) ⇒ Object



65
66
67
# File 'lib/types/class.rb', line 65

def self.Class(base = Object)
	Class.new(base)
end

.Hash(key_type, value_type) ⇒ Object



64
65
66
# File 'lib/types/hash.rb', line 64

def self.Hash(key_type, value_type)
	Hash.new(key_type, value_type)
end

.Lambda(*argument_types, returns: nil) ⇒ Object



62
63
64
# File 'lib/types/lambda.rb', line 62

def self.Lambda(*argument_types, returns: nil)
	Lambda.new(argument_types, returns)
end

.Method(receiver_type, *argument_types, returns: nil) ⇒ Object



74
75
76
# File 'lib/types/method.rb', line 74

def self.Method(receiver_type, *argument_types, returns: nil)
	Method.new(receiver_type, argument_types, returns)
end

.parse(signature) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/types.rb', line 45

def self.parse(signature)
	if signature =~ VALID_SIGNATURE
		eval(signature, binding)
	else
		raise ArgumentError, "Invalid type signature: #{signature.inspect}!"
	end
end

.Tuple(*item_types) ⇒ Object



66
67
68
# File 'lib/types/tuple.rb', line 66

def self.Tuple(*item_types)
	Tuple.new(item_types)
end