/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. 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.size-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.size-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.size-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.size-1) { |i| print v[i],"; " }
  23. puts