Class: Pione::Lang::PioneMethod
- Inherits:
-
StructX
- Object
- StructX
- Pione::Lang::PioneMethod
- Defined in:
- lib/pione/lang/pione-method.rb
Overview
PioneMethod is a class represents method in PIONE system.
Instance Method Summary collapse
-
#call(env, receiver, args) ⇒ Object
Call the method with recevier and arguemnts.
-
#get_input_types(env, receiver) ⇒ Object
Get the input types of receiver.
-
#get_output_type(env, receiver) ⇒ Object
Get the output type of receiver.
-
#validate_inputs(env, rec, args) ⇒ Boolean
Validate inputs data types for the method.
-
#validate_output(env, receiver, value) ⇒ Object
Validate output data type for the method.
Instance Method Details
#call(env, receiver, args) ⇒ Object
Call the method with recevier and arguemnts.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pione/lang/pione-method.rb', line 41 def call(env, receiver, args) _output = receiver.pione_type(env).instance_exec(env, receiver, *args, &body) if _output.nil? p self p receiver p args end validate_output(env, receiver, _output) return _output end |
#get_input_types(env, receiver) ⇒ Object
Get the input types of receiver.
83 84 85 |
# File 'lib/pione/lang/pione-method.rb', line 83 def get_input_types(env, receiver) inputs.map{|input| get_type(env, input, receiver)} end |
#get_output_type(env, receiver) ⇒ Object
Get the output type of receiver.
88 89 90 |
# File 'lib/pione/lang/pione-method.rb', line 88 def get_output_type(env, receiver) get_type(env, output, receiver) end |
#validate_inputs(env, rec, args) ⇒ Boolean
Validate inputs data types for the method.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pione/lang/pione-method.rb', line 60 def validate_inputs(env, rec, args) # check size return false unless inputs.size == args.size # check type inputs.each_with_index do |input, i| input = get_type(env, input, rec) unless input.match(env, args[i]) return false end end return true end |
#validate_output(env, receiver, value) ⇒ Object
Validate output data type for the method.
75 76 77 78 79 80 |
# File 'lib/pione/lang/pione-method.rb', line 75 def validate_output(env, receiver, value) _output = get_type(env, output, receiver) unless _output.match(env, value) raise MethodInterfaceError.new(:output, name, [_output], [value]) end end |