/tags/Root-branch-php-utl/SWIG/Examples/ruby/std_vector/runme.rb
Ruby | 36 lines | 16 code | 13 blank | 7 comment | 0 complexity | c2c59a7ac50e5db6b340903d0201bdb0 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
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.length-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.length-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.length-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.length-1) { |i| print v[i],"; " }
35puts
36