PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-15/SWIG/Examples/ruby/class/runme.rb

#
Ruby | 49 lines | 22 code | 14 blank | 13 comment | 1 complexity | 2e8621822932109465e74e691b0caa36 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.rb
  2. # This file illustrates the C++ interface created by SWIG.
  3. # All of our C++ classes get converted into Ruby classes.
  4. require 'example'
  5. # ----- Object creation -----
  6. print "Creating some objects:\n"
  7. c = Example::Circle.new(10)
  8. print " Created circle #{c}\n"
  9. s = Example::Square.new(10)
  10. print " Created square #{s}\n"
  11. # ----- Access a static member -----
  12. print "\nA total of #{Example::Shape.nshapes} shapes were created\n"
  13. # ----- Member data access -----
  14. # Set the location of the object
  15. # Notice how we can do this using functions specific to
  16. # the 'Circle' class.
  17. c.x = 20
  18. c.y = 30
  19. # Now use the same functions in the base class
  20. s.x = -10
  21. s.y = 5
  22. print "\nHere is their current position:\n"
  23. print " Circle = (", c.x, ",", c.y, ")\n"
  24. print " Square = (", s.x, ",", s.y, ")\n"
  25. # ----- Call some methods -----
  26. print "\nHere are some properties of the shapes:\n"
  27. for o in [c, s]
  28. print " #{o}\n"
  29. print " area = ", o.area, "\n"
  30. print " perimeter = ", o.perimeter, "\n"
  31. end
  32. # Notice how the Shape#area() and Shape#perimeter() functions really
  33. # invoke the appropriate virtual method on each object.
  34. print "\n", Example::Shape.nshapes," shapes remain\n"
  35. print "Goodbye\n"