Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/opl.rb
Instance Method Summary collapse
Instance Method Details
#dimension ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/opl.rb', line 65 def dimension a = self return 0 if a.class != Array result = 1 a.each do |sub_a| if sub_a.class == Array dim = sub_a.dimension result = dim + 1 if dim + 1 > result end end return result end |
#values_at_a(indices, current_array = self) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/opl.rb', line 78 def values_at_a(indices, current_array=self) #in: self = [3,4,[6,5,[3,4]],3], indices = [2,2,0] #out: 3 if indices.size == 1 return(current_array[indices[0]]) else values_at_a(indices[1..-1], current_array[indices[0]]) end end |