PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/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. require 'example'
  3. # Call average with a Ruby array...
  4. puts Example::average([1,2,3,4])
  5. # ... or a wrapped std::vector<int>
  6. v = Example::IntVector.new(4)
  7. 0.upto(v.length-1) { |i| v[i] = i+1 }
  8. puts Example::average(v)
  9. # half will return a Ruby array.
  10. # Call it with a Ruby array...
  11. w = Example::half([1.0, 1.5, 2.0, 2.5, 3.0])
  12. 0.upto(w.length-1) { |i| print w[i],"; " }
  13. puts
  14. # ... or a wrapped std::vector<double>
  15. v = Example::DoubleVector.new
  16. [1,2,3,4].each { |i| v.push(i) }
  17. w = Example::half(v)
  18. 0.upto(w.length-1) { |i| print w[i],"; " }
  19. puts
  20. # now halve a wrapped std::vector<double> in place
  21. Example::halve_in_place(v)
  22. 0.upto(v.length-1) { |i| print v[i],"; " }
  23. puts