Class: Array
Direct Known Subclasses
BaseVariable, BlockContainer, CallContainer, ClassName, Declaration, History, InstanceCall, InstanceCallStructure, MappingValues, MethodUsage, ParametersContainer, RealisedStatement, Requirement, RuntimeClass, ScopeDependencies, StatementDependencies, StatementGroup, StatementStructure, StatementStructure2, This
Instance Method Summary
collapse
Instance Method Details
#cauldron_method_calls ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/ruby_code/Array.rb', line 3
def cauldron_method_calls
result = ['.length','.any?','[]']
return result
end
|
#contains?(&block) ⇒ Boolean
This is a variation on the ‘any?’ except if the array contains an array it continue the search into that array.
TODO This method could probably be cleaned up a bit
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ruby_code/Array.rb', line 57
def contains?(&block)
self.each do |x|
if x.respond_to?(:contains?)
if x.contains?(&block)
return true
end
end
return true if block.call(x)
end
return false
end
|
39
40
41
42
43
44
|
# File 'lib/ruby_code/Array.rb', line 39
def copy
raise StandardError.new('No "copy" method has been created for '+self.class.to_s) unless self.class.to_s == 'Array'
result = []
self.each {|x| result.push(x.copy) }
return result
end
|
#select_all(results = [], &block) ⇒ Object
Returns all the elements that match the selection criteria just like the select method. However if it contains an array it will seach the array as well.
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/ruby_code/Array.rb', line 77
def select_all(results=[],&block)
self.each do |x|
if block.call(x)
results.push(x)
end
if x.respond_to?(:select_all)
x.select_all(results,&block)
end
end
return results
end
|
#to_declaration ⇒ Object
Returns the array as a declaration string e.g. [‘lions’,‘tigers’,‘bears’] becomes “[‘lion’,‘tigers’,‘bears’]”
23
24
25
26
|
# File 'lib/ruby_code/Array.rb', line 23
def to_declaration
raise StandardError.new('No to_declaration method has been created for '+self.class.to_s) unless self.class.to_s == 'Array'
return LiteralDeclaration.new(self.clone)
end
|
#to_intrinsic ⇒ Object
89
90
91
92
93
|
# File 'lib/ruby_code/Array.rb', line 89
def to_intrinsic
return IntrinsicTestCases.new if self.any? {|x| x.kind_of?(CTestCase)}
raise StandardError.new('Can not be converted to intrinsic instance '+self.class.to_s)
end
|
#to_literal ⇒ Object
46
47
48
|
# File 'lib/ruby_code/Array.rb', line 46
def to_literal
return Literal.new(self.copy.collect {|x| x.to_literal})
end
|
#to_var(id = nil, unique_id = nil) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/ruby_code/Array.rb', line 11
def to_var(id=nil,unique_id=nil)
raise StandardError.new('No to_var method has been created for '+self.class.to_s) unless self.class.to_s == 'Array'
result = []
self.each {|x| result.push(x.copy)}
replicate = ArrayVariable.new(*result) {{:variable_id => id,:uniq_id=>unique_id}}
return replicate
end
|
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/ruby_code/Array.rb', line 28
def write
raise StandardError.new('No "write" method has been created for '+self.class.to_s) unless self.class.to_s == 'Array'
line = '['
self.each do |x|
line += x.write
unless x.object_id == self.last.object_id then line += ', ' end
end
line += ']'
return line
end
|