Class: Types::Lambda
Overview
Represents a lambda (function) type with argument and return types.
“‘ruby type = Types::Lambda(Types::String, Types::Integer, returns: Types::String) type.to_s # => “Lambda(String, Integer, returns: String)” “`
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
Parses the input as a lambda/proc.
- #to_s ⇒ Object
Methods included from Generic
Constructor Details
#initialize(argument_types, return_type) ⇒ Lambda
Returns a new instance of Lambda.
20 21 22 23 |
# File 'lib/types/lambda.rb', line 20 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.
26 27 28 |
# File 'lib/types/lambda.rb', line 26 def argument_types @argument_types end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
28 29 30 |
# File 'lib/types/lambda.rb', line 28 def return_type @return_type end |
Instance Method Details
#parse(input) ⇒ Object
Parses the input as a lambda/proc.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/types/lambda.rb', line 48 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
36 37 38 39 40 41 42 |
# File 'lib/types/lambda.rb', line 36 def to_s if @return_type "Lambda(#{@argument_types.join(', ')}, returns: #{@return_type})" else "Lambda(#{@argument_types.join(', ')})" end end |