Class: MethodParameter
- Inherits:
-
BaseVariable
- Object
- Array
- BaseVariable
- MethodParameter
- Defined in:
- lib/core/variable/MethodParameter.rb
Instance Attribute Summary collapse
-
#usage_variable ⇒ Object
Returns a reference to the usage variable that is represented by this variable.
-
#variable_id ⇒ Object
writeonly
Sets the attribute variable_id.
Attributes inherited from BaseVariable
#instance_variable, #uniq_id_history, #value, #variable_id
Attributes included from Variable
Instance Method Summary collapse
- #copy ⇒ Object
-
#declaration_statement ⇒ Object
Returns a statement showing the variable being declaraced.
- #describe(tab = 0, context = self) ⇒ Object
-
#initialize(id = nil) ⇒ MethodParameter
constructor
A new instance of MethodParameter.
-
#literalise ⇒ Object
Attempts to return a literal that meets all the requirements.
-
#meets_requirements?(of) ⇒ Boolean
Returns true if this variables meets the requirements of the supplied variable.
- #to_declaration ⇒ Object
-
#to_literal_string ⇒ Object
Raises an error to avoid me accidently trying to give this class the method.
Methods inherited from BaseVariable
#destructive_instance_calls, #find_actual_variable, #instance_calls, #realised?, reset_global_id, #returning_instance_calls, #write, #write_with_uniq_id
Methods included from Variable
#increament_uniq_id!, reset_global_id, #to_var, variable_id
Methods included from VariableIncluded
#find_actual_variable, #variable
Methods inherited from Array
#cauldron_method_calls, #contains?, #select_all, #to_intrinsic, #to_literal, #to_var, #write
Constructor Details
#initialize(id = nil) ⇒ MethodParameter
Returns a new instance of MethodParameter.
5 6 7 |
# File 'lib/core/variable/MethodParameter.rb', line 5 def initialize(id=nil) super(id) end |
Instance Attribute Details
#usage_variable ⇒ Object
Returns a reference to the usage variable that is represented by this variable. Remember this MethodParameter represents a particular rule so its id doesn’t reflect all cases.
85 86 87 |
# File 'lib/core/variable/MethodParameter.rb', line 85 def usage_variable @usage_variable end |
#variable_id=(value) ⇒ Object (writeonly)
Sets the attribute variable_id
3 4 5 |
# File 'lib/core/variable/MethodParameter.rb', line 3 def variable_id=(value) @variable_id = value end |
Instance Method Details
#copy ⇒ Object
77 78 79 |
# File 'lib/core/variable/MethodParameter.rb', line 77 def copy return Marshal.load(Marshal.dump(self)) end |
#declaration_statement ⇒ Object
Returns a statement showing the variable being declaraced
MethodParameter.new(Requirement.new())
115 116 117 118 |
# File 'lib/core/variable/MethodParameter.rb', line 115 def declaration_statement # TODO Check that .copy method call works across all the uses of "declaration_statement" return Statement.new(ClassMethodCallContainer.new(MethodParameterClass.new,New.new,*self.collect {|x| x.copy.declaration_statement})) end |
#describe(tab = 0, context = self) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/core/variable/MethodParameter.rb', line 47 def describe(tab=0,context=self) # Create a temporay copy of the variable copied_var = self.copy unless context == self # Return a duplicate variable with the requirements in the context indicated copied_var = context.contextual_variable(copied_var.variable_id) end # Print the name of the variable line = '' line += write # Print out each of the requirements copied_var.each do |x| desc = x.describe(context) desc.each_line do |l| line += "\t"+l end line += "\n" unless x == copied_var.last end line += "\n" return line end |
#literalise ⇒ Object
Attempts to return a literal that meets all the requirements.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/core/variable/MethodParameter.rb', line 99 def literalise # Does the variable have any "equal to literal" requirements self.each do |req| if req.structure_match?([This,Equal,Literal]) return req[2].copy end end raise StandardError.new('The literalise call is very basic right now and needs improved') end |
#meets_requirements?(of) ⇒ Boolean
Returns true if this variables meets the requirements of the supplied variable. If the this meets the requirements of the supplied variable then this variable could replace the supplied variable in a statement.
TODO Write tests for this
TODO Have an act_as call that doesn’t return true/false but raises errors so I can identify
why something can't be something else.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/core/variable/MethodParameter.rb', line 21 def meets_requirements? of # Handle the possible datatypes of "of" begin if of.kind_of?(Variable) return meets_requirements_of_variable(of) elsif of.kind_of?(InstanceCallContainer) return meets_requirements_of_instance_call(of) else raise StandardError.new('Not expecting class of type '+of.class.to_s) end rescue FailedVariableMatch return false end end |
#to_declaration ⇒ Object
120 121 122 |
# File 'lib/core/variable/MethodParameter.rb', line 120 def to_declaration return VariableDeclaration.new('MethodParameter',*self.collect {|x| x.to_declaration}) end |
#to_literal_string ⇒ Object
Raises an error to avoid me accidently trying to give this class the method.
40 41 42 43 44 |
# File 'lib/core/variable/MethodParameter.rb', line 40 def to_literal_string # TODO I should turn this on further down the line - it realtes to tracking #raise StandardError.new('Method Variables can\'t be converted to a literal string because they don\'t have a value') return self.write end |