aboutsummaryrefslogtreecommitdiff
path: root/Examples/ruby/operator/runme.rb
blob: 518d91e9edbc785b849b237639f668c067047d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Operator overloading example
require 'example'

include Example

a = Complex.new(2, 3)
b = Complex.new(-5, 10)

puts "a   = #{a}"
puts "b   = #{b}"

c = a + b
puts "c   = #{c}"
puts "a*b = #{a*b}"
puts "a-c = #{a-c}"

# This should invoke Complex's copy constructor
e = Complex.new(a-c)
e = a - c
puts "e   = #{e}"

# Big expression
f = ((a+b)*(c+b*e)) + (-a)
puts "f   = #{f}"