Class: DefCall

Inherits:
InstanceCall show all
Includes:
WriteParameters
Defined in:
lib/core/method_call/DefCall.rb

Overview

This class represent calls to availble functions. This could be custom generated method calls e.g.

m1

if there was a method that looked like

def m1

# do something

end

it could also be core ruby calls

TODO Write tests for this

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WriteParameters

#describe_params, #write_params

Methods inherited from InstanceCall

#closure, #destructive?, #requirements, #to_declaration, #to_literal_string, #use, #valid_syntax?

Methods inherited from Array

#cauldron_method_calls, #contains?, #select_all, #to_declaration, #to_intrinsic, #to_literal, #to_var

Constructor Details

#initialize(response, runtime_method, *parameters) ⇒ DefCall

TODO I suspect response isn’t needed any more or at least should be the secound parameter

Parameters:

  • response

    What is returned by the method -

Raises:

  • (StandardError)


27
28
29
30
31
32
33
# File 'lib/core/method_call/DefCall.rb', line 27

def initialize(response,runtime_method,*parameters)
  super(*parameters)
  raise StandardError.new('Should be a runtime method instance') unless runtime_method.kind_of?(ActsAsRuntimeMethod)
  @response = response.copy
  @runtime_method = runtime_method.copy

end

Instance Attribute Details

#runtime_methodObject (readonly)

TODO I’m still undecided on whether DefCall should have a scope id or not



20
21
22
# File 'lib/core/method_call/DefCall.rb', line 20

def runtime_method
  @runtime_method
end

#scope_idObject

TODO I’m still undecided on whether DefCall should have a scope id or not



20
21
22
# File 'lib/core/method_call/DefCall.rb', line 20

def scope_id
  @scope_id
end

Instance Method Details

#copyObject



46
47
48
# File 'lib/core/method_call/DefCall.rb', line 46

def copy
  return DefCall.new(@response.copy,@runtime_method.copy,*self.collect {|x| x.copy})
end

#describeObject



41
42
43
44
# File 'lib/core/method_call/DefCall.rb', line 41

def describe
  x = 'Call: '+write
  return x
end

#equivalent?(to) ⇒ Boolean

Returns:



64
65
66
67
68
69
70
# File 'lib/core/method_call/DefCall.rb', line 64

def equivalent?(to)
  return false unless to.class == self.class
  # TODO  I should also include a method_interation value here - this should increment each time the 
  #       the runtime method recieves a new statement because it essentially becomes a different method.
  return true if @runtime_method.method_id == to.runtime_method.method_id
  return false    
end

#pass_as?(variable_type) ⇒ Boolean

Returns true if the method call can pass as specified variable_type. This bascially depends on what the method call returns.

Parameters:

  • variable_type

    The variable type the method call will be treated as. For example FixnumVariable.

Returns:



60
61
62
# File 'lib/core/method_call/DefCall.rb', line 60

def pass_as?(variable_type)
  return @response.pass_as?(variable_type)
end

#responseObject



50
51
52
# File 'lib/core/method_call/DefCall.rb', line 50

def response
  return @response.copy
end

#writeObject



35
36
37
38
39
# File 'lib/core/method_call/DefCall.rb', line 35

def write
  l = @runtime_method.method_name
  l += write_params(self)
  return l
end