PageRenderTime 51ms CodeModel.GetById 44ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/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
 3# This file illustrates the C++ interface created by SWIG.
 4# All of our C++ classes get converted into Ruby classes.
 5
 6require 'example'
 7
 8# ----- Object creation -----
 9
10print "Creating some objects:\n"
11c = Example::Circle.new(10)
12print "    Created circle #{c}\n"
13s = Example::Square.new(10)
14print "    Created square #{s}\n"
15
16# ----- Access a static member -----
17
18print "\nA total of #{Example::Shape.nshapes} shapes were created\n"
19
20# ----- Member data access -----
21
22# Set the location of the object
23
24# Notice how we can do this using functions specific to
25# the 'Circle' class.
26c.x = 20
27c.y = 30
28
29# Now use the same functions in the base class
30s.x = -10
31s.y = 5
32
33print "\nHere is their current position:\n"
34print "    Circle = (", c.x, ",", c.y, ")\n"
35print "    Square = (", s.x, ",", s.y, ")\n"
36
37# ----- Call some methods -----
38
39print "\nHere are some properties of the shapes:\n"
40for o in [c, s]
41  print "    #{o}\n"
42  print "        area      = ", o.area, "\n"
43  print "        perimeter = ", o.perimeter, "\n"
44end
45# Notice how the Shape#area() and Shape#perimeter() functions really
46# invoke the appropriate virtual method on each object.
47
48print "\n", Example::Shape.nshapes," shapes remain\n"
49print "Goodbye\n"