/trunk/Examples/ruby/reference/runme.rb
Ruby | 60 lines | 17 code | 15 blank | 28 comment | 0 complexity | 3ce2716ba2d047d57fc9609452c165de MD5 | raw file
1# file: runme.rb 2 3# This file illustrates the manipulation of C++ references in Ruby. 4 5require 'example' 6 7# ----- Object creation ----- 8 9print "Creating some objects:\n" 10a = Example::Vector.new(3,4,5) 11b = Example::Vector.new(10,11,12) 12 13print " Created ", a.print, "\n" 14print " Created ", b.print, "\n" 15 16# ----- Call an overloaded operator ----- 17 18# This calls the wrapper we placed around 19# 20# operator+(const Vector &a, const Vector &) 21# 22# It returns a new allocated object. 23 24print "Adding a+b\n" 25c = Example::addv(a, b) 26print " a+b = ", c.print, "\n" 27 28# ----- Create a vector array ----- 29 30print "Creating an array of vectors\n" 31va = Example::VectorArray.new(10) 32print " va = #{va}\n" 33 34# ----- Set some values in the array ----- 35 36# These operators copy the value of a and b to the vector array 37va.set(0, a) 38va.set(1, b) 39 40va.set(2, Example::addv(a,b)) 41 42c = Example::addv(a,b) 43va.set(3, c) 44 45=begin commented out due to GC issue 46 47# Get some values from the array 48 49print "Getting some array values\n" 50for i in 0...5 51 print " va(#{i}) = ", va.get(i).print, "\n" 52end 53 54# Watch under resource meter to check on this 55print "Making sure we don't leak memory.\n" 56for i in 0...1000000 57 c = va.get(i % 10) 58end 59 60=end