Class: Types::Lambda

Inherits:
Object
  • Object
show all
Includes:
Generic
Defined in:
lib/types/lambda.rb

Overview

A lambda that represents a function (or callable object).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generic

#|

Constructor Details

#initialize(argument_types, return_type) ⇒ Lambda

Returns a new instance of Lambda.



30
31
32
33
# File 'lib/types/lambda.rb', line 30

def initialize(argument_types, return_type)
	@argument_types = argument_types
	@return_type = return_type
end

Instance Attribute Details

#argument_typesObject (readonly)

Returns the value of attribute argument_types.



35
36
37
# File 'lib/types/lambda.rb', line 35

def argument_types
  @argument_types
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



36
37
38
# File 'lib/types/lambda.rb', line 36

def return_type
  @return_type
end

Instance Method Details

#composite?Boolean

Returns:



38
39
40
# File 'lib/types/lambda.rb', line 38

def composite?
	true
end

#parse(input) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/types/lambda.rb', line 50

def parse(input)
	case input
	when ::String
		eval("lambda{#{input}}", TOPLEVEL_BINDING)
	when ::Proc
		input
	else
		raise ArgumentError, "Cannot coerce #{input.inpsect} into Lambda!"
	end
end

#to_sObject



42
43
44
45
46
47
48
# File 'lib/types/lambda.rb', line 42

def to_s
	if @return_type
		"Lambda(#{@argument_types.join(', ')}, returns: #{@return_type})"
	else
		"Lambda(#{@argument_types.join(', ')})"
	end
end