PageRenderTime 25ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/ruby/std_vector/runme.rb

#
Ruby | 36 lines | 16 code | 13 blank | 7 comment | 0 complexity | bf952877b656574f58e0e16923401106 MD5 | raw file
 1# file: runme.rb
 2
 3require 'example'
 4
 5# Call average with a Ruby array...
 6
 7puts Example::average([1,2,3,4])
 8
 9# ... or a wrapped std::vector<int>
10
11v = Example::IntVector.new(4)
120.upto(v.size-1) { |i| v[i] = i+1 }
13puts Example::average(v)
14
15
16# half will return a Ruby array.
17# Call it with a Ruby array...
18
19w = Example::half([1.0, 1.5, 2.0, 2.5, 3.0])
200.upto(w.size-1) { |i| print w[i],"; " }
21puts
22
23# ... or a wrapped std::vector<double>
24
25v = Example::DoubleVector.new
26[1,2,3,4].each { |i| v.push(i) }
27w = Example::half(v)
280.upto(w.size-1) { |i| print w[i],"; " }
29puts
30
31# now halve a wrapped std::vector<double> in place
32
33Example::halve_in_place(v)
340.upto(v.size-1) { |i| print v[i],"; " }
35puts
36