Class: Types::Lambda
Overview
A lambda that represents a function (or callable object).
Instance Attribute Summary collapse
-
#argument_types ⇒ Object
readonly
Returns the value of attribute argument_types.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
Instance Method Summary collapse
- #composite? ⇒ Boolean
-
#initialize(argument_types, return_type) ⇒ Lambda
constructor
A new instance of Lambda.
- #parse(input) ⇒ Object
- #to_s ⇒ Object
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_types ⇒ Object (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_type ⇒ Object (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
#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_s ⇒ Object
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 |